Commit 99c4da00c7d0e9c4ec212443971d8ce35abb6910
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/342' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/342 Conflicts: plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
Showing
30 changed files
with
270 additions
and
237 deletions
Show diff stats
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
@@ -802,7 +802,7 @@ class Environment < ActiveRecord::Base | @@ -802,7 +802,7 @@ class Environment < ActiveRecord::Base | ||
802 | end | 802 | end |
803 | 803 | ||
804 | def highlighted_products_with_image(options = {}) | 804 | def highlighted_products_with_image(options = {}) |
805 | - Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) | 805 | + Product.find(:all, {:conditions => {:highlighted => true, :profile_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) |
806 | end | 806 | end |
807 | 807 | ||
808 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 | 808 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 |
app/models/product.rb
@@ -15,7 +15,11 @@ class Product < ActiveRecord::Base | @@ -15,7 +15,11 @@ 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 | ||
20 | + alias_method :enterprise=, :profile= | ||
21 | + alias_method :enterprise, :profile | ||
22 | + | ||
19 | has_one :region, :through => :enterprise | 23 | has_one :region, :through => :enterprise |
20 | validates_presence_of :enterprise | 24 | validates_presence_of :enterprise |
21 | 25 | ||
@@ -29,7 +33,10 @@ class Product < ActiveRecord::Base | @@ -29,7 +33,10 @@ class Product < ActiveRecord::Base | ||
29 | has_many :qualifiers, :through => :product_qualifiers | 33 | has_many :qualifiers, :through => :product_qualifiers |
30 | has_many :certifiers, :through => :product_qualifiers | 34 | has_many :certifiers, :through => :product_qualifiers |
31 | 35 | ||
32 | - validates_uniqueness_of :name, :scope => :enterprise_id, :allow_nil => true | 36 | + acts_as_having_settings :field => :data |
37 | + | ||
38 | + validates_uniqueness_of :name, :scope => :profile_id, :allow_nil => true, :if => :validate_uniqueness_of_column_name? | ||
39 | + | ||
33 | validates_presence_of :product_category_id | 40 | validates_presence_of :product_category_id |
34 | validates_associated :product_category | 41 | validates_associated :product_category |
35 | 42 | ||
@@ -234,4 +241,10 @@ class Product < ActiveRecord::Base | @@ -234,4 +241,10 @@ class Product < ActiveRecord::Base | ||
234 | 241 | ||
235 | delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise | 242 | delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise |
236 | 243 | ||
244 | + protected | ||
245 | + | ||
246 | + def validate_uniqueness_of_column_name? | ||
247 | + true | ||
248 | + end | ||
249 | + | ||
237 | end | 250 | end |
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 |
db/migrate/20130703124306_add_archived_field_to_products.rb
0 → 100644
db/schema.rb
@@ -415,7 +415,7 @@ ActiveRecord::Schema.define(:version => 20140108132730) do | @@ -415,7 +415,7 @@ ActiveRecord::Schema.define(:version => 20140108132730) do | ||
415 | end | 415 | end |
416 | 416 | ||
417 | create_table "products", :force => true do |t| | 417 | create_table "products", :force => true do |t| |
418 | - t.integer "enterprise_id" | 418 | + t.integer "profile_id" |
419 | t.integer "product_category_id" | 419 | t.integer "product_category_id" |
420 | t.string "name" | 420 | t.string "name" |
421 | t.decimal "price" | 421 | t.decimal "price" |
@@ -427,10 +427,13 @@ ActiveRecord::Schema.define(:version => 20140108132730) do | @@ -427,10 +427,13 @@ ActiveRecord::Schema.define(:version => 20140108132730) do | ||
427 | t.boolean "highlighted", :default => false | 427 | t.boolean "highlighted", :default => false |
428 | t.integer "unit_id" | 428 | t.integer "unit_id" |
429 | t.integer "image_id" | 429 | t.integer "image_id" |
430 | + t.string "type" | ||
431 | + t.text "data" | ||
432 | + t.boolean "archived", :default => false | ||
430 | end | 433 | end |
431 | 434 | ||
432 | - add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" | ||
433 | add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" | 435 | add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" |
436 | + add_index "products", ["profile_id"], :name => "index_products_on_profile_id" | ||
434 | 437 | ||
435 | create_table "profiles", :force => true do |t| | 438 | create_table "profiles", :force => true do |t| |
436 | t.string "name" | 439 | t.string "name" |
lib/tasks/plugins.rake
1 | +require 'active_record' | ||
2 | +require_dependency 'active_record/migration' | ||
3 | + | ||
4 | +class ActiveRecord::Migrator | ||
5 | + alias_method :orig_initialize, :initialize | ||
6 | + def initialize *args | ||
7 | + orig_initialize *args | ||
8 | + @migrations_path = "{db/migrate,config/plugins/*/db/migrate}" | ||
9 | + end | ||
10 | +end | ||
11 | + | ||
1 | namespace :noosfero do | 12 | namespace :noosfero do |
2 | namespace :plugins do | 13 | namespace :plugins do |
3 | - plugin_migration_dirs = Dir.glob(File.join(Rails.root, 'config', 'plugins', '*', 'db', 'migrate')) | 14 | + plugin_migration_dirs = Dir.glob(File.join(Rails.root, 'config', |
15 | + 'plugins', '*', 'db', 'migrate')) | ||
4 | task :migrate do | 16 | task :migrate do |
5 | plugin_migration_dirs.each do |path| | 17 | plugin_migration_dirs.each do |path| |
6 | - ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) | ||
7 | - end | ||
8 | - end | ||
9 | - task :abort_if_pending_migrations do | ||
10 | - if defined? ActiveRecord | ||
11 | - pending_migrations = plugin_migration_dirs.map do |path| | ||
12 | - ActiveRecord::Migrator.new(:up, path).pending_migrations | ||
13 | - end.flatten | ||
14 | - | ||
15 | - if pending_migrations.any? | ||
16 | - puts "You have #{pending_migrations.size} pending migrations:" | ||
17 | - pending_migrations.each do |pending_migration| | ||
18 | - puts ' %4d %s' % [pending_migration.version, pending_migration.name] | ||
19 | - end | ||
20 | - abort %{Run "rake db:migrate" to update your database then try again.} | ||
21 | - end | 18 | + ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? |
19 | + ENV["VERSION"].to_i : nil) | ||
22 | end | 20 | end |
23 | end | 21 | end |
24 | end | 22 | end |
25 | end | 23 | end |
26 | - | ||
27 | -task 'db:migrate' => 'noosfero:plugins:migrate' | ||
28 | -task 'db:abort_if_pending_migrations' => 'noosfero:plugins:abort_if_pending_migrations' |
plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb
@@ -199,7 +199,7 @@ class BscPluginMyprofileController < MyProfileController | @@ -199,7 +199,7 @@ class BscPluginMyprofileController < 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 < Enterprise | @@ -2,7 +2,7 @@ class BscPlugin::Bsc < 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 < ActionController::TestCase | @@ -308,9 +308,9 @@ class BscPluginMyprofileControllerTest < 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 < ActiveSupport::TestCase | @@ -6,7 +6,7 @@ class ProductTest < 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 < PublicController | @@ -13,12 +13,12 @@ class ShoppingCartPluginController < 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 < PublicController | @@ -29,7 +29,7 @@ class ShoppingCartPluginController < 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 => { |
@@ -96,7 +96,7 @@ class ShoppingCartPluginController < PublicController | @@ -96,7 +96,7 @@ class ShoppingCartPluginController < PublicController | ||
96 | def buy | 96 | def buy |
97 | if validate_cart_presence | 97 | if validate_cart_presence |
98 | @cart = cart | 98 | @cart = cart |
99 | - @enterprise = environment.enterprises.find(cart[:enterprise_id]) | 99 | + @enterprise = environment.enterprises.find(cart[:profile_id]) |
100 | @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) | 100 | @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) |
101 | render :layout => false | 101 | render :layout => false |
102 | end | 102 | end |
@@ -105,7 +105,7 @@ class ShoppingCartPluginController < PublicController | @@ -105,7 +105,7 @@ class ShoppingCartPluginController < PublicController | ||
105 | def send_request | 105 | def send_request |
106 | register_order(params[:customer], self.cart[:items]) | 106 | register_order(params[:customer], self.cart[:items]) |
107 | begin | 107 | begin |
108 | - enterprise = environment.enterprises.find(cart[:enterprise_id]) | 108 | + enterprise = environment.enterprises.find(cart[:profile_id]) |
109 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) | 109 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) |
110 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) | 110 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) |
111 | self.cart = nil | 111 | self.cart = nil |
@@ -168,7 +168,7 @@ class ShoppingCartPluginController < PublicController | @@ -168,7 +168,7 @@ class ShoppingCartPluginController < PublicController | ||
168 | end | 168 | end |
169 | 169 | ||
170 | def update_delivery_option | 170 | def update_delivery_option |
171 | - enterprise = environment.enterprises.find(cart[:enterprise_id]) | 171 | + enterprise = environment.enterprises.find(cart[:profile_id]) |
172 | settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) | 172 | settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) |
173 | delivery_price = settings.delivery_options[params[:delivery_option]] | 173 | delivery_price = settings.delivery_options[params[:delivery_option]] |
174 | delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) | 174 | delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) |
@@ -189,7 +189,7 @@ class ShoppingCartPluginController < PublicController | @@ -189,7 +189,7 @@ class ShoppingCartPluginController < PublicController | ||
189 | private | 189 | private |
190 | 190 | ||
191 | def validate_same_enterprise(product) | 191 | def validate_same_enterprise(product) |
192 | - if self.cart && self.cart[:enterprise_id] && product.enterprise_id != self.cart[:enterprise_id] | 192 | + if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] |
193 | render :text => { | 193 | render :text => { |
194 | :ok => false, | 194 | :ok => false, |
195 | :error => { | 195 | :error => { |
@@ -268,7 +268,7 @@ class ShoppingCartPluginController < PublicController | @@ -268,7 +268,7 @@ class ShoppingCartPluginController < PublicController | ||
268 | new_items[id] = {:quantity => quantity, :price => price, :name => product.name} | 268 | new_items[id] = {:quantity => quantity, :price => price, :name => product.name} |
269 | end | 269 | end |
270 | ShoppingCartPlugin::PurchaseOrder.create!( | 270 | ShoppingCartPlugin::PurchaseOrder.create!( |
271 | - :seller => Enterprise.find(cart[:enterprise_id]), | 271 | + :seller => Enterprise.find(cart[:profile_id]), |
272 | :customer => user, | 272 | :customer => user, |
273 | :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, | 273 | :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, |
274 | :products_list => new_items, | 274 | :products_list => new_items, |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -11,7 +11,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -11,7 +11,7 @@ class ShoppingCartPluginControllerTest < 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 < ActionController::TestCase | @@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest < 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 < ActionController::TestCase | @@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest < 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 < ActionController::TestCase | @@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest < 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 < ActionController::TestCase | @@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest < 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 < ActionController::TestCase | @@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest < 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/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
@@ -81,9 +81,9 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -81,9 +81,9 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
81 | end | 81 | end |
82 | 82 | ||
83 | should 'group filtered orders products and quantities' do | 83 | should 'group filtered orders products and quantities' do |
84 | - p1 = fast_create(Product, :enterprise_id => enterprise.id, :price => 1, :name => 'p1') | ||
85 | - p2 = fast_create(Product, :enterprise_id => enterprise.id, :price => 2, :name => 'p2') | ||
86 | - p3 = fast_create(Product, :enterprise_id => enterprise.id, :price => 3) | 84 | + p1 = fast_create(Product, :profile_id => enterprise.id, :price => 1, :name => 'p1') |
85 | + p2 = fast_create(Product, :profile_id => enterprise.id, :price => 2, :name => 'p2') | ||
86 | + p3 = fast_create(Product, :profile_id => enterprise.id, :price => 3) | ||
87 | po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} | 87 | po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} |
88 | po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} | 88 | po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} |
89 | po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | 89 | po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) |
plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb
@@ -20,7 +20,7 @@ class ShoppingCartPluginTest < ActiveSupport::TestCase | @@ -20,7 +20,7 @@ class ShoppingCartPluginTest < ActiveSupport::TestCase | ||
20 | 20 | ||
21 | should 'not add button if product unavailable' do | 21 | should 'not add button if product unavailable' do |
22 | enterprise = fast_create(:enterprise) | 22 | enterprise = fast_create(:enterprise) |
23 | - product = fast_create(Product, :available => false, :enterprise_id => enterprise.id) | 23 | + product = fast_create(Product, :available => false, :profile_id => enterprise.id) |
24 | enterprise.stubs(:shopping_cart).returns(true) | 24 | enterprise.stubs(:shopping_cart).returns(true) |
25 | 25 | ||
26 | assert_nil shopping_cart.add_to_cart_button(product) | 26 | assert_nil shopping_cart.add_to_cart_button(product) |
plugins/solr/test/functional/search_controller_test.rb
@@ -81,7 +81,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -81,7 +81,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -159,7 +159,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -183,13 +183,13 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -216,9 +216,9 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -235,8 +235,8 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -246,9 +246,9 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -269,11 +269,11 @@ class SearchControllerTest < 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 < ActiveSupport::TestCase | @@ -11,7 +11,7 @@ class EnterpriseTest < 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 < ActiveSupport::TestCase | @@ -13,7 +13,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -23,7 +23,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -39,7 +39,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -70,28 +70,28 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -100,8 +100,8 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -110,14 +110,14 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -133,10 +133,10 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -145,18 +145,18 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -165,23 +165,23 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -195,8 +195,8 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -206,10 +206,10 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -221,9 +221,9 @@ class ProductTest < 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 |
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
@@ -19,7 +19,7 @@ class CatalogControllerTest < ActionController::TestCase | @@ -19,7 +19,7 @@ class CatalogControllerTest < ActionController::TestCase | ||
19 | def test_local_files_reference | 19 | def test_local_files_reference |
20 | assert_local_files_reference :get, :index, :profile => @enterprise.identifier | 20 | assert_local_files_reference :get, :index, :profile => @enterprise.identifier |
21 | end | 21 | end |
22 | - | 22 | + |
23 | def test_valid_xhtml | 23 | def test_valid_xhtml |
24 | assert_valid_xhtml | 24 | assert_valid_xhtml |
25 | end | 25 | end |
@@ -34,7 +34,7 @@ class CatalogControllerTest < ActionController::TestCase | @@ -34,7 +34,7 @@ class CatalogControllerTest < ActionController::TestCase | ||
34 | get :index, :profile => 'testent' | 34 | get :index, :profile => 'testent' |
35 | assert_response :success | 35 | assert_response :success |
36 | end | 36 | end |
37 | - | 37 | + |
38 | should 'list products of enterprise' do | 38 | should 'list products of enterprise' do |
39 | get :index, :profile => @enterprise.identifier | 39 | get :index, :profile => @enterprise.identifier |
40 | assert_kind_of Array, assigns(:products) | 40 | assert_kind_of Array, assigns(:products) |
@@ -42,7 +42,7 @@ class CatalogControllerTest < ActionController::TestCase | @@ -42,7 +42,7 @@ class CatalogControllerTest < ActionController::TestCase | ||
42 | 42 | ||
43 | should 'paginate enterprise products list' do | 43 | should 'paginate enterprise products list' do |
44 | 1.upto(12).map do | 44 | 1.upto(12).map do |
45 | - fast_create(Product, :enterprise_id => @enterprise.id) | 45 | + fast_create(Product, :profile_id => @enterprise.id) |
46 | end | 46 | end |
47 | 47 | ||
48 | assert_equal 12, @enterprise.products.count | 48 | assert_equal 12, @enterprise.products.count |
@@ -92,7 +92,7 @@ class CatalogControllerTest < ActionController::TestCase | @@ -92,7 +92,7 @@ class CatalogControllerTest < ActionController::TestCase | ||
92 | end | 92 | end |
93 | end | 93 | end |
94 | 94 | ||
95 | - product = fast_create(Product, :enterprise_id => @enterprise.id) | 95 | + product = fast_create(Product, :profile_id => @enterprise.id) |
96 | environment = Environment.default | 96 | environment = Environment.default |
97 | environment.enable_plugin(Plugin1.name) | 97 | environment.enable_plugin(Plugin1.name) |
98 | environment.enable_plugin(Plugin2.name) | 98 | environment.enable_plugin(Plugin2.name) |
@@ -108,10 +108,10 @@ class CatalogControllerTest < ActionController::TestCase | @@ -108,10 +108,10 @@ class CatalogControllerTest < ActionController::TestCase | ||
108 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) | 108 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
109 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) | 109 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
110 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) | 110 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) |
111 | - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | ||
112 | - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | ||
113 | - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | ||
114 | - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | 111 | + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) |
112 | + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) | ||
113 | + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) | ||
114 | + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) | ||
115 | 115 | ||
116 | get :index, :profile => @enterprise.identifier, :level => pc1.id | 116 | get :index, :profile => @enterprise.identifier, :level => pc1.id |
117 | 117 | ||
@@ -126,10 +126,10 @@ class CatalogControllerTest < ActionController::TestCase | @@ -126,10 +126,10 @@ class CatalogControllerTest < ActionController::TestCase | ||
126 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) | 126 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
127 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) | 127 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
128 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) | 128 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) |
129 | - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | ||
130 | - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | ||
131 | - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | ||
132 | - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | 129 | + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) |
130 | + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) | ||
131 | + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) | ||
132 | + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) | ||
133 | 133 | ||
134 | get :index, :profile => @enterprise.identifier, :level => pc2.id | 134 | get :index, :profile => @enterprise.identifier, :level => pc2.id |
135 | 135 | ||
@@ -140,12 +140,12 @@ class CatalogControllerTest < ActionController::TestCase | @@ -140,12 +140,12 @@ class CatalogControllerTest < ActionController::TestCase | ||
140 | end | 140 | end |
141 | 141 | ||
142 | should 'get products ordered by availability, highlighted and then name' do | 142 | should 'get products ordered by availability, highlighted and then name' do |
143 | - p1 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Zebra', :available => true, :highlighted => true) | ||
144 | - p2 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Car', :available => true) | ||
145 | - p3 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Panda', :available => true) | ||
146 | - p4 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Pen', :available => false, :highlighted => true) | ||
147 | - p5 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Ball', :available => false) | ||
148 | - p6 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Medal', :available => false) | 143 | + p1 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Zebra', :available => true, :highlighted => true) |
144 | + p2 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Car', :available => true) | ||
145 | + p3 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Panda', :available => true) | ||
146 | + p4 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Pen', :available => false, :highlighted => true) | ||
147 | + p5 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Ball', :available => false) | ||
148 | + p6 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Medal', :available => false) | ||
149 | 149 | ||
150 | get :index, :profile => @enterprise.identifier | 150 | get :index, :profile => @enterprise.identifier |
151 | 151 | ||
@@ -175,10 +175,10 @@ class CatalogControllerTest < ActionController::TestCase | @@ -175,10 +175,10 @@ class CatalogControllerTest < ActionController::TestCase | ||
175 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) | 175 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
176 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) | 176 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
177 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) | 177 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) |
178 | - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | ||
179 | - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | ||
180 | - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | ||
181 | - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | 178 | + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) |
179 | + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) | ||
180 | + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) | ||
181 | + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) | ||
182 | 182 | ||
183 | get :index, :profile => @enterprise.identifier | 183 | get :index, :profile => @enterprise.identifier |
184 | 184 | ||
@@ -194,10 +194,10 @@ class CatalogControllerTest < ActionController::TestCase | @@ -194,10 +194,10 @@ class CatalogControllerTest < ActionController::TestCase | ||
194 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) | 194 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
195 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) | 195 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
196 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) | 196 | pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) |
197 | - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | ||
198 | - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | ||
199 | - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | ||
200 | - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | 197 | + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) |
198 | + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) | ||
199 | + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) | ||
200 | + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) | ||
201 | 201 | ||
202 | get :index, :profile => @enterprise.identifier, :level => pc4.id | 202 | get :index, :profile => @enterprise.identifier, :level => pc4.id |
203 | 203 | ||
@@ -209,8 +209,8 @@ class CatalogControllerTest < ActionController::TestCase | @@ -209,8 +209,8 @@ class CatalogControllerTest < ActionController::TestCase | ||
209 | 209 | ||
210 | should 'add product status on the class css' do | 210 | should 'add product status on the class css' do |
211 | category = ProductCategory.create!(:name => "Cateogry", :environment => @enterprise.environment) | 211 | category = ProductCategory.create!(:name => "Cateogry", :environment => @enterprise.environment) |
212 | - p1 = fast_create(Product, :product_category_id => category.id, :enterprise_id => @enterprise.id, :highlighted => true) | ||
213 | - p2 = fast_create(Product, :product_category_id => category.id, :enterprise_id => @enterprise.id, :available => false) | 212 | + p1 = fast_create(Product, :product_category_id => category.id, :profile_id => @enterprise.id, :highlighted => true) |
213 | + p2 = fast_create(Product, :product_category_id => category.id, :profile_id => @enterprise.id, :available => false) | ||
214 | 214 | ||
215 | get :index, :profile => @enterprise.identifier | 215 | get :index, :profile => @enterprise.identifier |
216 | 216 | ||
@@ -225,10 +225,10 @@ class CatalogControllerTest < ActionController::TestCase | @@ -225,10 +225,10 @@ class CatalogControllerTest < ActionController::TestCase | ||
225 | pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) | 225 | pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) |
226 | pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) | 226 | pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) |
227 | pc4 = ProductCategory.create!(:name => "Pies", :environment => environment) | 227 | pc4 = ProductCategory.create!(:name => "Pies", :environment => environment) |
228 | - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | ||
229 | - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | ||
230 | - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | ||
231 | - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | 228 | + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) |
229 | + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) | ||
230 | + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) | ||
231 | + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) | ||
232 | 232 | ||
233 | get :index, :profile => @enterprise.identifier | 233 | get :index, :profile => @enterprise.identifier |
234 | 234 | ||
@@ -236,8 +236,8 @@ class CatalogControllerTest < ActionController::TestCase | @@ -236,8 +236,8 @@ class CatalogControllerTest < ActionController::TestCase | ||
236 | end | 236 | end |
237 | 237 | ||
238 | should 'use price_detail name instead of production_cost name straight' do | 238 | should 'use price_detail name instead of production_cost name straight' do |
239 | - p1 = fast_create(Product, :product_category_id => @product_category.id, :enterprise_id => @enterprise.id) | ||
240 | - p2 = fast_create(Product, :product_category_id => @product_category.id, :enterprise_id => @enterprise.id) | 239 | + p1 = fast_create(Product, :product_category_id => @product_category.id, :profile_id => @enterprise.id) |
240 | + p2 = fast_create(Product, :product_category_id => @product_category.id, :profile_id => @enterprise.id) | ||
241 | Product.any_instance.stubs(:price_described?).returns(true) | 241 | Product.any_instance.stubs(:price_described?).returns(true) |
242 | production_cost = fast_create(ProductionCost) | 242 | production_cost = fast_create(ProductionCost) |
243 | pd1 = PriceDetail.create!(:product => p1, :production_cost => production_cost) | 243 | pd1 = PriceDetail.create!(:product => p1, :production_cost => production_cost) |
test/functional/manage_products_controller_test.rb
@@ -21,11 +21,11 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -21,11 +21,11 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
21 | def test_local_files_reference | 21 | def test_local_files_reference |
22 | assert_local_files_reference :get, :index, :profile => @enterprise.identifier | 22 | assert_local_files_reference :get, :index, :profile => @enterprise.identifier |
23 | end | 23 | end |
24 | - | 24 | + |
25 | def test_valid_xhtml | 25 | def test_valid_xhtml |
26 | assert_valid_xhtml | 26 | assert_valid_xhtml |
27 | end | 27 | end |
28 | - | 28 | + |
29 | should "not have permission" do | 29 | should "not have permission" do |
30 | u = create_user('user_test') | 30 | u = create_user('user_test') |
31 | login_as :user_test | 31 | login_as :user_test |
@@ -45,7 +45,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -45,7 +45,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
45 | assert_response :success | 45 | assert_response :success |
46 | assert assigns(:product) | 46 | assert assigns(:product) |
47 | assert_template 'new' | 47 | assert_template 'new' |
48 | - assert_tag :tag => 'form', :attributes => { :action => /new/ } | 48 | + assert_tag :tag => 'form', :attributes => { :action => /new/ } |
49 | end | 49 | end |
50 | 50 | ||
51 | should "create new product" do | 51 | should "create new product" do |
@@ -66,7 +66,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -66,7 +66,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
66 | end | 66 | end |
67 | 67 | ||
68 | should "get edit name form" do | 68 | should "get edit name form" do |
69 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 69 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
70 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'name' | 70 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'name' |
71 | assert_response :success | 71 | assert_response :success |
72 | assert assigns(:product) | 72 | assert assigns(:product) |
@@ -74,7 +74,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -74,7 +74,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
74 | end | 74 | end |
75 | 75 | ||
76 | should "get edit info form" do | 76 | should "get edit info form" do |
77 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 77 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
78 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info' | 78 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info' |
79 | assert_response :success | 79 | assert_response :success |
80 | assert assigns(:product) | 80 | assert assigns(:product) |
@@ -82,7 +82,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -82,7 +82,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
82 | end | 82 | end |
83 | 83 | ||
84 | should "get edit image form" do | 84 | should "get edit image form" do |
85 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 85 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
86 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'image' | 86 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'image' |
87 | assert_response :success | 87 | assert_response :success |
88 | assert assigns(:product) | 88 | assert assigns(:product) |
@@ -90,7 +90,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -90,7 +90,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
90 | end | 90 | end |
91 | 91 | ||
92 | should "edit product name" do | 92 | should "edit product name" do |
93 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 93 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
94 | post :edit, :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => product.id, :field => 'name' | 94 | post :edit, :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => product.id, :field => 'name' |
95 | assert_response :success | 95 | assert_response :success |
96 | assert assigns(:product) | 96 | assert assigns(:product) |
@@ -99,7 +99,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -99,7 +99,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
99 | end | 99 | end |
100 | 100 | ||
101 | should "edit product description" do | 101 | should "edit product description" do |
102 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id, :description => 'My product is very good') | 102 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id, :description => 'My product is very good') |
103 | post :edit, :profile => @enterprise.identifier, :product => {:description => 'A very good product!'}, :id => product.id, :field => 'info' | 103 | post :edit, :profile => @enterprise.identifier, :product => {:description => 'A very good product!'}, :id => product.id, :field => 'info' |
104 | assert_response :success | 104 | assert_response :success |
105 | assert assigns(:product) | 105 | assert assigns(:product) |
@@ -108,7 +108,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -108,7 +108,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
108 | end | 108 | end |
109 | 109 | ||
110 | should "edit product image" do | 110 | should "edit product image" do |
111 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 111 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
112 | post :edit, :profile => @enterprise.identifier, :product => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }, :id => product.id, :field => 'image' | 112 | post :edit, :profile => @enterprise.identifier, :product => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }, :id => product.id, :field => 'image' |
113 | assert_response :success | 113 | assert_response :success |
114 | assert assigns(:product) | 114 | assert assigns(:product) |
@@ -117,32 +117,32 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -117,32 +117,32 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
117 | end | 117 | end |
118 | 118 | ||
119 | should "not edit to invalid parameters" do | 119 | should "not edit to invalid parameters" do |
120 | - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 120 | + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
121 | post 'edit_category', :profile => @enterprise.identifier, :selected_category_id => nil, :id => product.id | 121 | post 'edit_category', :profile => @enterprise.identifier, :selected_category_id => nil, :id => product.id |
122 | assert_response :success | 122 | assert_response :success |
123 | assert_template 'shared/_dialog_error_messages' | 123 | assert_template 'shared/_dialog_error_messages' |
124 | end | 124 | end |
125 | 125 | ||
126 | should "not crash if product has no category" do | 126 | should "not crash if product has no category" do |
127 | - product = fast_create(Product, :enterprise_id => @enterprise.id) | 127 | + product = fast_create(Product, :profile_id => @enterprise.id) |
128 | assert_nothing_raised do | 128 | assert_nothing_raised do |
129 | post 'edit_category', :profile => @enterprise.identifier, :id => product.id | 129 | post 'edit_category', :profile => @enterprise.identifier, :id => product.id |
130 | end | 130 | end |
131 | end | 131 | end |
132 | 132 | ||
133 | should "destroy product" do | 133 | should "destroy product" do |
134 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 134 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
135 | assert_difference Product, :count, -1 do | 135 | assert_difference Product, :count, -1 do |
136 | post 'destroy', :profile => @enterprise.identifier, :id => product.id | 136 | post 'destroy', :profile => @enterprise.identifier, :id => product.id |
137 | assert_response :redirect | 137 | assert_response :redirect |
138 | assert_redirected_to :action => 'index' | 138 | assert_redirected_to :action => 'index' |
139 | assert assigns(:product) | 139 | assert assigns(:product) |
140 | assert ! Product.find_by_name('test product') | 140 | assert ! Product.find_by_name('test product') |
141 | - end | 141 | + end |
142 | end | 142 | end |
143 | 143 | ||
144 | should "fail to destroy product" do | 144 | should "fail to destroy product" do |
145 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 145 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
146 | Product.any_instance.stubs(:destroy).returns(false) | 146 | Product.any_instance.stubs(:destroy).returns(false) |
147 | assert_no_difference Product, :count do | 147 | assert_no_difference Product, :count do |
148 | post 'destroy', :profile => @enterprise.identifier, :id => product.id | 148 | post 'destroy', :profile => @enterprise.identifier, :id => product.id |
@@ -185,11 +185,11 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -185,11 +185,11 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
185 | end | 185 | end |
186 | 186 | ||
187 | should 'filter html with white list from description of product' do | 187 | should 'filter html with white list from description of product' do |
188 | - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 188 | + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
189 | post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>" } | 189 | post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>" } |
190 | assert_equal "<b>descr bold</b>", assigns(:product).description | 190 | assert_equal "<b>descr bold</b>", assigns(:product).description |
191 | end | 191 | end |
192 | - | 192 | + |
193 | should 'not let users in if environment do not let' do | 193 | should 'not let users in if environment do not let' do |
194 | env = Environment.default | 194 | env = Environment.default |
195 | env.disable('products_for_enterprises') | 195 | env.disable('products_for_enterprises') |
@@ -280,14 +280,14 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -280,14 +280,14 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
280 | end | 280 | end |
281 | 281 | ||
282 | should 'not show product price when showing product if not informed' do | 282 | should 'not show product price when showing product if not informed' do |
283 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 283 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
284 | get :show, :id => product.id, :profile => @enterprise.identifier | 284 | get :show, :id => product.id, :profile => @enterprise.identifier |
285 | 285 | ||
286 | assert_no_tag :tag => 'span', :attributes => { :class => 'product_price' }, :content => /Price:/ | 286 | assert_no_tag :tag => 'span', :attributes => { :class => 'product_price' }, :content => /Price:/ |
287 | end | 287 | end |
288 | 288 | ||
289 | should 'show product price when showing product if unit was informed' do | 289 | should 'show product price when showing product if unit was informed' do |
290 | - 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) | 290 | + 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) |
291 | get :show, :id => product.id, :profile => @enterprise.identifier | 291 | get :show, :id => product.id, :profile => @enterprise.identifier |
292 | 292 | ||
293 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ | 293 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ |
@@ -295,7 +295,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -295,7 +295,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
295 | end | 295 | end |
296 | 296 | ||
297 | should 'show product price when showing product if discount was informed' do | 297 | should 'show product price when showing product if discount was informed' do |
298 | - 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) | 298 | + 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) |
299 | get :show, :id => product.id, :profile => @enterprise.identifier | 299 | get :show, :id => product.id, :profile => @enterprise.identifier |
300 | 300 | ||
301 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /List price:/ | 301 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /List price:/ |
@@ -305,7 +305,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -305,7 +305,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
305 | end | 305 | end |
306 | 306 | ||
307 | should 'show product price when showing product if unit not informed' do | 307 | should 'show product price when showing product if unit not informed' do |
308 | - product = fast_create(Product, :name => 'test product', :price => 50.00, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 308 | + product = fast_create(Product, :name => 'test product', :price => 50.00, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
309 | get :show, :id => product.id, :profile => @enterprise.identifier | 309 | get :show, :id => product.id, :profile => @enterprise.identifier |
310 | 310 | ||
311 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ | 311 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ |
@@ -313,7 +313,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -313,7 +313,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
313 | end | 313 | end |
314 | 314 | ||
315 | should 'display button to add input when product has no input' do | 315 | should 'display button to add input when product has no input' do |
316 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 316 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
317 | get :show, :id => product.id, :profile => @enterprise.identifier | 317 | get :show, :id => product.id, :profile => @enterprise.identifier |
318 | 318 | ||
319 | assert_tag :tag => 'div', :attributes => { :id => 'display-add-input-button'}, | 319 | assert_tag :tag => 'div', :attributes => { :id => 'display-add-input-button'}, |
@@ -321,13 +321,13 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -321,13 +321,13 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
321 | end | 321 | end |
322 | 322 | ||
323 | should 'has instance of input list when showing product' do | 323 | should 'has instance of input list when showing product' do |
324 | - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 324 | + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
325 | get :show, :id => product.id, :profile => @enterprise.identifier | 325 | get :show, :id => product.id, :profile => @enterprise.identifier |
326 | assert_equal [], assigns(:inputs) | 326 | assert_equal [], assigns(:inputs) |
327 | end | 327 | end |
328 | 328 | ||
329 | should 'remove input of a product' do | 329 | should 'remove input of a product' do |
330 | - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 330 | + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
331 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) | 331 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
332 | assert_equal [input], product.inputs | 332 | assert_equal [input], product.inputs |
333 | 333 | ||
@@ -337,7 +337,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -337,7 +337,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
337 | end | 337 | end |
338 | 338 | ||
339 | should 'save inputs order' do | 339 | should 'save inputs order' do |
340 | - product = fast_create(Product, :enterprise_id => @enterprise.id) | 340 | + product = fast_create(Product, :profile_id => @enterprise.id) |
341 | first = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) | 341 | first = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) |
342 | second = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) | 342 | second = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) |
343 | third = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) | 343 | third = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) |
@@ -358,7 +358,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -358,7 +358,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
358 | should 'not list all the products of enterprise' do | 358 | should 'not list all the products of enterprise' do |
359 | @enterprise.products = [] | 359 | @enterprise.products = [] |
360 | 1.upto(12) do |n| | 360 | 1.upto(12) do |n| |
361 | - fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 361 | + fast_create(Product, :name => "test product_#{n}", :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
362 | end | 362 | end |
363 | get :index, :profile => @enterprise.identifier | 363 | get :index, :profile => @enterprise.identifier |
364 | assert_equal 10, assigns(:products).count | 364 | assert_equal 10, assigns(:products).count |
@@ -367,7 +367,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -367,7 +367,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
367 | should 'paginate the manage products list of enterprise' do | 367 | should 'paginate the manage products list of enterprise' do |
368 | @enterprise.products = [] | 368 | @enterprise.products = [] |
369 | 1.upto(12) do |n| | 369 | 1.upto(12) do |n| |
370 | - fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 370 | + fast_create(Product, :name => "test product_#{n}", :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
371 | end | 371 | end |
372 | get :index, :profile => @enterprise.identifier | 372 | get :index, :profile => @enterprise.identifier |
373 | assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" } | 373 | assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" } |
@@ -377,7 +377,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -377,7 +377,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
377 | end | 377 | end |
378 | 378 | ||
379 | should 'display tabs even if description and inputs are empty and user is allowed' do | 379 | should 'display tabs even if description and inputs are empty and user is allowed' do |
380 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 380 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
381 | get :show, :id => product.id, :profile => @enterprise.identifier | 381 | get :show, :id => product.id, :profile => @enterprise.identifier |
382 | 382 | ||
383 | assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } | 383 | assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } |
@@ -388,7 +388,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -388,7 +388,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
388 | 388 | ||
389 | login_as 'foo' | 389 | login_as 'foo' |
390 | 390 | ||
391 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 391 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
392 | get :show, :id => product.id, :profile => @enterprise.identifier | 392 | get :show, :id => product.id, :profile => @enterprise.identifier |
393 | 393 | ||
394 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } | 394 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } |
@@ -397,7 +397,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -397,7 +397,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
397 | should 'not display tabs if description and inputs are empty and user is not logged in' do | 397 | should 'not display tabs if description and inputs are empty and user is not logged in' do |
398 | logout | 398 | logout |
399 | 399 | ||
400 | - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 400 | + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
401 | get :show, :id => product.id, :profile => @enterprise.identifier | 401 | get :show, :id => product.id, :profile => @enterprise.identifier |
402 | 402 | ||
403 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } | 403 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } |
@@ -407,7 +407,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -407,7 +407,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
407 | create_user('foo') | 407 | create_user('foo') |
408 | 408 | ||
409 | login_as 'foo' | 409 | login_as 'foo' |
410 | - product = fast_create(Product, :description => 'This product is very good', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 410 | + product = fast_create(Product, :description => 'This product is very good', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
411 | get :show, :id => product.id, :profile => @enterprise.identifier | 411 | get :show, :id => product.id, :profile => @enterprise.identifier |
412 | assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#product-description'}, :content => 'Description'} | 412 | assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#product-description'}, :content => 'Description'} |
413 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#inputs'}, :content => 'Inputs and raw material'} | 413 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#inputs'}, :content => 'Inputs and raw material'} |
@@ -417,7 +417,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -417,7 +417,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
417 | create_user 'foo' | 417 | create_user 'foo' |
418 | 418 | ||
419 | login_as 'foo' | 419 | login_as 'foo' |
420 | - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 420 | + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
421 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) | 421 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
422 | 422 | ||
423 | get :show, :id => product.id, :profile => @enterprise.identifier | 423 | get :show, :id => product.id, :profile => @enterprise.identifier |
@@ -429,7 +429,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -429,7 +429,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
429 | create_user('foo') | 429 | create_user('foo') |
430 | 430 | ||
431 | login_as 'foo' | 431 | login_as 'foo' |
432 | - product = fast_create(Product, :description => 'This product is very good', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 432 | + product = fast_create(Product, :description => 'This product is very good', :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
433 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) | 433 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
434 | 434 | ||
435 | get :show, :id => product.id, :profile => @enterprise.identifier | 435 | get :show, :id => product.id, :profile => @enterprise.identifier |
@@ -449,7 +449,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -449,7 +449,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
449 | end | 449 | end |
450 | end | 450 | end |
451 | 451 | ||
452 | - product = fast_create(Product, :enterprise_id => @enterprise.id) | 452 | + product = fast_create(Product, :profile_id => @enterprise.id) |
453 | 453 | ||
454 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProductInfoExtras1Plugin.new, TestProductInfoExtras2Plugin.new]) | 454 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProductInfoExtras1Plugin.new, TestProductInfoExtras2Plugin.new]) |
455 | 455 | ||
@@ -471,7 +471,7 @@ class ManageProductsControllerTest < ActionController::TestCase | @@ -471,7 +471,7 @@ class ManageProductsControllerTest < ActionController::TestCase | ||
471 | end | 471 | end |
472 | 472 | ||
473 | should 'remove price detail of a product' do | 473 | should 'remove price detail of a product' do |
474 | - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) | 474 | + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) |
475 | cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'Environment') | 475 | cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'Environment') |
476 | detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) | 476 | detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) |
477 | 477 |
test/functional/map_balloon_controller_test.rb
@@ -18,26 +18,26 @@ class MapBalloonControllerTest < ActionController::TestCase | @@ -18,26 +18,26 @@ class MapBalloonControllerTest < 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 < ActionController::TestCase | @@ -166,7 +166,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -191,7 +191,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -348,15 +348,15 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -394,7 +394,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -590,7 +590,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -605,7 +605,7 @@ class SearchControllerTest < 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_equivalent [a, a2], assigns(:searches)[:tag][:results] | 611 | assert_equivalent [a, a2], assigns(:searches)[:tag][:results] |
@@ -621,7 +621,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -621,7 +621,7 @@ class SearchControllerTest < 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 < ActionController::TestCase | @@ -632,22 +632,22 @@ class SearchControllerTest < 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 < ActiveSupport::TestCase | @@ -393,13 +393,13 @@ class EnterpriseTest < 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 < ActiveSupport::TestCase | @@ -407,7 +407,7 @@ class EnterpriseTest < 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
@@ -384,13 +384,13 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -384,13 +384,13 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
384 | p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) | 384 | p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) |
385 | products = [] | 385 | products = [] |
386 | 3.times {|n| | 386 | 3.times {|n| |
387 | - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, | 387 | + products.push(Product.create!(:name => "product #{n}", :profile_id => e1.id, |
388 | :product_category_id => category.id, :highlighted => true, | 388 | :product_category_id => category.id, :highlighted => true, |
389 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | 389 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } |
390 | )) | 390 | )) |
391 | } | 391 | } |
392 | - Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => category.id, :highlighted => true) | ||
393 | - Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => category.id, :image_builder => { | 392 | + Product.create!(:name => "product 4", :profile_id => e1.id, :product_category_id => category.id, :highlighted => true) |
393 | + Product.create!(:name => "product 5", :profile_id => e1.id, :product_category_id => category.id, :image_builder => { | ||
394 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | 394 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
395 | }) | 395 | }) |
396 | assert_equal products, env.highlighted_products_with_image | 396 | assert_equal products, env.highlighted_products_with_image |
@@ -718,7 +718,7 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -718,7 +718,7 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
718 | assert_equal c, e.portal_community | 718 | assert_equal c, e.portal_community |
719 | e.unset_portal_community! | 719 | e.unset_portal_community! |
720 | e.reload | 720 | e.reload |
721 | - assert_nil e.portal_community | 721 | + assert_nil e.portal_community |
722 | assert_equal [], e.portal_folders | 722 | assert_equal [], e.portal_folders |
723 | assert_equal 0, e.news_amount_by_folder | 723 | assert_equal 0, e.news_amount_by_folder |
724 | assert_equal false, e.enabled?('use_portal_community') | 724 | assert_equal false, e.enabled?('use_portal_community') |
test/unit/featured_products_block_test.rb
@@ -13,7 +13,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -13,7 +13,7 @@ class FeaturedProductsBlockTest < 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 < ActiveSupport::TestCase | @@ -66,7 +66,7 @@ class FeaturedProductsBlockTest < 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 < ActiveSupport::TestCase | @@ -82,7 +82,7 @@ class FeaturedProductsBlockTest < 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 < ActiveSupport::TestCase | @@ -95,7 +95,7 @@ class FeaturedProductsBlockTest < 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 < ActiveSupport::TestCase | @@ -118,13 +118,13 @@ class FeaturedProductsBlockTest < 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 < ActiveSupport::TestCase | @@ -115,7 +115,7 @@ class InputTest < 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 < ActiveSupport::TestCase | @@ -134,7 +134,7 @@ class InputTest < 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 < ActiveSupport::TestCase | @@ -144,7 +144,7 @@ class InputTest < 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 < ActiveSupport::TestCase | @@ -70,7 +70,7 @@ class PriceDetailTest < 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 < ActiveSupport::TestCase | @@ -7,12 +7,12 @@ class ProductCategoryTest < 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 < ActiveSupport::TestCase | @@ -18,14 +18,14 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -84,7 +84,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -138,7 +138,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -197,7 +197,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -217,7 +217,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -225,14 +225,14 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -254,7 +254,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -262,7 +262,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -414,7 +414,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -423,7 +423,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -433,7 +433,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -445,7 +445,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -460,7 +460,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -490,7 +490,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -505,7 +505,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -516,7 +516,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -526,7 +526,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -535,7 +535,7 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -543,9 +543,9 @@ class ProductTest < 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 < ActiveSupport::TestCase | @@ -579,9 +579,9 @@ class ProductTest < 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 |