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 | 10 | |
11 | 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 | 14 | has_many :inputs, :through => :products |
15 | 15 | has_many :production_costs, :as => :owner |
16 | 16 | ... | ... |
app/models/environment.rb
... | ... | @@ -802,7 +802,7 @@ class Environment < ActiveRecord::Base |
802 | 802 | end |
803 | 803 | |
804 | 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 | 806 | end |
807 | 807 | |
808 | 808 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 | ... | ... |
app/models/product.rb
... | ... | @@ -15,7 +15,11 @@ class Product < ActiveRecord::Base |
15 | 15 | 'full' |
16 | 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 | 23 | has_one :region, :through => :enterprise |
20 | 24 | validates_presence_of :enterprise |
21 | 25 | |
... | ... | @@ -29,7 +33,10 @@ class Product < ActiveRecord::Base |
29 | 33 | has_many :qualifiers, :through => :product_qualifiers |
30 | 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 | 40 | validates_presence_of :product_category_id |
34 | 41 | validates_associated :product_category |
35 | 42 | |
... | ... | @@ -234,4 +241,10 @@ class Product < ActiveRecord::Base |
234 | 241 | |
235 | 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 | 250 | end | ... | ... |
db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb
0 → 100644
... | ... | @@ -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 | 415 | end |
416 | 416 | |
417 | 417 | create_table "products", :force => true do |t| |
418 | - t.integer "enterprise_id" | |
418 | + t.integer "profile_id" | |
419 | 419 | t.integer "product_category_id" |
420 | 420 | t.string "name" |
421 | 421 | t.decimal "price" |
... | ... | @@ -427,10 +427,13 @@ ActiveRecord::Schema.define(:version => 20140108132730) do |
427 | 427 | t.boolean "highlighted", :default => false |
428 | 428 | t.integer "unit_id" |
429 | 429 | t.integer "image_id" |
430 | + t.string "type" | |
431 | + t.text "data" | |
432 | + t.boolean "archived", :default => false | |
430 | 433 | end |
431 | 434 | |
432 | - add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" | |
433 | 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 | 438 | create_table "profiles", :force => true do |t| |
436 | 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 | 12 | namespace :noosfero do |
2 | 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 | 16 | task :migrate do |
5 | 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 | 20 | end |
23 | 21 | end |
24 | 22 | end |
25 | 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 | 199 | enterprises = enterprises.blank? ? -1 : enterprises |
200 | 200 | added_products = (params[:added_products] || []).split(',') |
201 | 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 | 203 | map {|product| { :id => product.id, |
204 | 204 | :name => short_text(product_display_name(product), 60), |
205 | 205 | :sale_id => params[:sale_id], | ... | ... |
plugins/bsc/lib/bsc_plugin/bsc.rb
... | ... | @@ -2,7 +2,7 @@ class BscPlugin::Bsc < Enterprise |
2 | 2 | |
3 | 3 | has_many :enterprises |
4 | 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 | 6 | has_many :contracts, :class_name => 'BscPlugin::Contract' |
7 | 7 | |
8 | 8 | validates_presence_of :nickname | ... | ... |
plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb
... | ... | @@ -308,9 +308,9 @@ class BscPluginMyprofileControllerTest < ActionController::TestCase |
308 | 308 | enterprise1 = fast_create(Enterprise) |
309 | 309 | enterprise2 = fast_create(Enterprise) |
310 | 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 | 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 | 6 | should 'return have bsc' do |
7 | 7 | bsc = BscPlugin::Bsc.create!({:business_name => 'Sample Bsc', :identifier => 'sample-bsc', :company_name => 'Sample Bsc Ltda.', :cnpj => VALID_CNPJ}) |
8 | 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 | 11 | assert_equal bsc, product.bsc |
12 | 12 | end | ... | ... |
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
... | ... | @@ -13,12 +13,12 @@ class ShoppingCartPluginController < PublicController |
13 | 13 | def get |
14 | 14 | config = |
15 | 15 | if cart.nil? |
16 | - { :enterprise_id => nil, | |
16 | + { :profile_id => nil, | |
17 | 17 | :has_products => false, |
18 | 18 | :visible => false, |
19 | 19 | :products => []} |
20 | 20 | else |
21 | - { :enterprise_id => cart[:enterprise_id], | |
21 | + { :profile_id => cart[:profile_id], | |
22 | 22 | :has_products => (cart[:items].keys.size > 0), |
23 | 23 | :visible => visible?, |
24 | 24 | :products => products} |
... | ... | @@ -29,7 +29,7 @@ class ShoppingCartPluginController < PublicController |
29 | 29 | def add |
30 | 30 | product = find_product(params[:id]) |
31 | 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 | 33 | self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? |
34 | 34 | self.cart[:items][product.id] += 1 |
35 | 35 | render :text => { |
... | ... | @@ -96,7 +96,7 @@ class ShoppingCartPluginController < PublicController |
96 | 96 | def buy |
97 | 97 | if validate_cart_presence |
98 | 98 | @cart = cart |
99 | - @enterprise = environment.enterprises.find(cart[:enterprise_id]) | |
99 | + @enterprise = environment.enterprises.find(cart[:profile_id]) | |
100 | 100 | @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) |
101 | 101 | render :layout => false |
102 | 102 | end |
... | ... | @@ -105,7 +105,7 @@ class ShoppingCartPluginController < PublicController |
105 | 105 | def send_request |
106 | 106 | register_order(params[:customer], self.cart[:items]) |
107 | 107 | begin |
108 | - enterprise = environment.enterprises.find(cart[:enterprise_id]) | |
108 | + enterprise = environment.enterprises.find(cart[:profile_id]) | |
109 | 109 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) |
110 | 110 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) |
111 | 111 | self.cart = nil |
... | ... | @@ -168,7 +168,7 @@ class ShoppingCartPluginController < PublicController |
168 | 168 | end |
169 | 169 | |
170 | 170 | def update_delivery_option |
171 | - enterprise = environment.enterprises.find(cart[:enterprise_id]) | |
171 | + enterprise = environment.enterprises.find(cart[:profile_id]) | |
172 | 172 | settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) |
173 | 173 | delivery_price = settings.delivery_options[params[:delivery_option]] |
174 | 174 | delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) |
... | ... | @@ -189,7 +189,7 @@ class ShoppingCartPluginController < PublicController |
189 | 189 | private |
190 | 190 | |
191 | 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 | 193 | render :text => { |
194 | 194 | :ok => false, |
195 | 195 | :error => { |
... | ... | @@ -268,7 +268,7 @@ class ShoppingCartPluginController < PublicController |
268 | 268 | new_items[id] = {:quantity => quantity, :price => price, :name => product.name} |
269 | 269 | end |
270 | 270 | ShoppingCartPlugin::PurchaseOrder.create!( |
271 | - :seller => Enterprise.find(cart[:enterprise_id]), | |
271 | + :seller => Enterprise.find(cart[:profile_id]), | |
272 | 272 | :customer => user, |
273 | 273 | :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, |
274 | 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 | 11 | @request = ActionController::TestRequest.new |
12 | 12 | @response = ActionController::TestResponse.new |
13 | 13 | @enterprise = fast_create(Enterprise) |
14 | - @product = fast_create(Product, :enterprise_id => @enterprise.id) | |
14 | + @product = fast_create(Product, :profile_id => @enterprise.id) | |
15 | 15 | end |
16 | 16 | attr_reader :enterprise |
17 | 17 | attr_reader :product |
... | ... | @@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
62 | 62 | end |
63 | 63 | |
64 | 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 | 66 | get :add, :id => product.id |
67 | 67 | get :add, :id => another_product.id |
68 | 68 | |
... | ... | @@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
135 | 135 | end |
136 | 136 | |
137 | 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 | 139 | get :add, :id => product.id |
140 | 140 | get :add, :id => another_product.id |
141 | 141 | |
... | ... | @@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
150 | 150 | end |
151 | 151 | |
152 | 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 | 156 | assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do |
157 | 157 | post :send_request, |
158 | 158 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} |
... | ... | @@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
168 | 168 | end |
169 | 169 | |
170 | 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 | 173 | assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do |
174 | 174 | post :send_request, |
175 | 175 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} |
... | ... | @@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
181 | 181 | end |
182 | 182 | |
183 | 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 | 185 | post :add, :id => product1.id |
186 | 186 | post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } |
187 | 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 | 81 | end |
82 | 82 | |
83 | 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 | 87 | po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} |
88 | 88 | po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} |
89 | 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 | 20 | |
21 | 21 | should 'not add button if product unavailable' do |
22 | 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 | 24 | enterprise.stubs(:shopping_cart).returns(true) |
25 | 25 | |
26 | 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 | 81 | state = fast_create(State, :name => 'Acre', :acronym => 'AC') |
82 | 82 | city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) |
83 | 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 | 85 | qualifier1 = fast_create(Qualifier) |
86 | 86 | qualifier2 = fast_create(Qualifier) |
87 | 87 | prod.qualifiers_list = [[qualifier1.id, 0], [qualifier2.id, 0]] |
... | ... | @@ -159,7 +159,7 @@ class SearchControllerTest < ActionController::TestCase |
159 | 159 | prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) |
160 | 160 | ent = create_profile_with_optional_category(Enterprise, 'test enterprise') |
161 | 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 | 163 | end |
164 | 164 | |
165 | 165 | get :products |
... | ... | @@ -183,13 +183,13 @@ class SearchControllerTest < ActionController::TestCase |
183 | 183 | |
184 | 184 | cat = fast_create(ProductCategory) |
185 | 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 | 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 | 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 | 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 | 194 | get :products |
195 | 195 | assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products][:results].docs |
... | ... | @@ -216,9 +216,9 @@ class SearchControllerTest < ActionController::TestCase |
216 | 216 | |
217 | 217 | should 'order product results by more recent when requested' do |
218 | 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 | 223 | # change others attrs will make updated_at = Time.now for all |
224 | 224 | Product.record_timestamps = false |
... | ... | @@ -235,8 +235,8 @@ class SearchControllerTest < ActionController::TestCase |
235 | 235 | should 'only list products from enabled enterprises' do |
236 | 236 | ent1 = fast_create(Enterprise, :enabled => true) |
237 | 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 | 241 | get :products, :query => 'product' |
242 | 242 | |
... | ... | @@ -246,9 +246,9 @@ class SearchControllerTest < ActionController::TestCase |
246 | 246 | |
247 | 247 | should 'order product results by name when requested' do |
248 | 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 | 253 | prod3.update_attribute :name, 'product A' |
254 | 254 | prod2.update_attribute :name, 'product B' |
... | ... | @@ -269,11 +269,11 @@ class SearchControllerTest < ActionController::TestCase |
269 | 269 | |
270 | 270 | cat = fast_create(ProductCategory) |
271 | 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 | 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 | 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 | 278 | get :products, :query => 'product', :order_by => :closest |
279 | 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 | 11 | |
12 | 12 | should 'reindex when products are changed' do |
13 | 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 | 15 | Product.expects(:solr_batch_add_association).with(product, :enterprise) |
16 | 16 | product.update_attribute :name, "novo nome" |
17 | 17 | end | ... | ... |
plugins/solr/test/unit/product_test.rb
... | ... | @@ -13,7 +13,7 @@ class ProductTest < ActiveSupport::TestCase |
13 | 13 | should 'reindex enterprise after saving' do |
14 | 14 | ent = fast_create(Enterprise) |
15 | 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 | 17 | Product.expects(:solr_batch_add).with([ent]) |
18 | 18 | prod.save! |
19 | 19 | end |
... | ... | @@ -23,7 +23,7 @@ class ProductTest < ActiveSupport::TestCase |
23 | 23 | c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) |
24 | 24 | ent = fast_create(Enterprise, :region_id => c.id) |
25 | 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 | 27 | pq = p.product_qualifiers.create!(:qualifier => fast_create(Qualifier, :name => 'qualifier'), |
28 | 28 | :certifier => fast_create(Certifier, :name => 'certifier')) |
29 | 29 | assert_equal 'Related products', Product.facet_by_id(:solr_plugin_f_category)[:label] |
... | ... | @@ -39,7 +39,7 @@ class ProductTest < ActiveSupport::TestCase |
39 | 39 | c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) |
40 | 40 | ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun") |
41 | 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 | 43 | :product_category_id => category.id) |
44 | 44 | qual = Qualifier.create!(:name => 'qualificador', :environment_id => Environment.default.id) |
45 | 45 | cert = Certifier.create!(:name => 'certificador', :environment_id => Environment.default.id) |
... | ... | @@ -70,28 +70,28 @@ class ProductTest < ActiveSupport::TestCase |
70 | 70 | TestSolr.enable |
71 | 71 | ent = fast_create(Enterprise) |
72 | 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 | 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 | 76 | assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs |
77 | 77 | end |
78 | 78 | |
79 | 79 | should 'boost search results that include an image' do |
80 | 80 | TestSolr.enable |
81 | 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 | 83 | product_with_image = Product.create!(:name => 'product with image', :product_category => product_category, |
84 | 84 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, |
85 | - :enterprise_id => profile.id) | |
85 | + :profile_id => profile.id) | |
86 | 86 | assert_equal [product_with_image, product_without_image], Product.find_by_contents('product image')[:results].docs |
87 | 87 | end |
88 | 88 | |
89 | 89 | should 'boost search results that include qualifier' do |
90 | 90 | TestSolr.enable |
91 | 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 | 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 | 95 | product_with_q.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) |
96 | 96 | product_with_q.save! |
97 | 97 | |
... | ... | @@ -100,8 +100,8 @@ class ProductTest < ActiveSupport::TestCase |
100 | 100 | |
101 | 101 | should 'boost search results with open price' do |
102 | 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 | 105 | open_price.inputs << Input.new(:product => open_price, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10) |
106 | 106 | open_price.save! |
107 | 107 | |
... | ... | @@ -110,14 +110,14 @@ class ProductTest < ActiveSupport::TestCase |
110 | 110 | |
111 | 111 | should 'boost search results with solidarity inputs' do |
112 | 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 | 115 | Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, |
116 | 116 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) |
117 | 117 | Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, |
118 | 118 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) |
119 | 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 | 121 | Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, |
122 | 122 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) |
123 | 123 | Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, |
... | ... | @@ -133,10 +133,10 @@ class ProductTest < ActiveSupport::TestCase |
133 | 133 | |
134 | 134 | should 'boost available search results' do |
135 | 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 | 137 | product.available = false |
138 | 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 | 140 | product2.available = true |
141 | 141 | product2.save! |
142 | 142 | |
... | ... | @@ -145,18 +145,18 @@ class ProductTest < ActiveSupport::TestCase |
145 | 145 | |
146 | 146 | should 'boost search results created updated recently' do |
147 | 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 | 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 | 152 | assert_equal [product2, product], Product.find_by_contents('product')[:results].docs |
153 | 153 | end |
154 | 154 | |
155 | 155 | should 'boost search results with description' do |
156 | 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 | 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 | 160 | :description => 'a small description') |
161 | 161 | |
162 | 162 | assert_equal [product2, product], Product.find_by_contents('product')[:results].docs |
... | ... | @@ -165,23 +165,23 @@ class ProductTest < ActiveSupport::TestCase |
165 | 165 | should 'boost if enterprise is enabled' do |
166 | 166 | TestSolr.enable |
167 | 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 | 171 | assert_equal [product2, product], Product.find_by_contents('product')[:results].docs |
172 | 172 | end |
173 | 173 | |
174 | 174 | should 'combine different boost types' do |
175 | 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 | 177 | image_only = Product.create!(:name => 'product with image', :product_category => product_category, |
178 | 178 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, |
179 | - :enterprise_id => profile.id) | |
179 | + :profile_id => profile.id) | |
180 | 180 | qual_only = Product.create!(:name => 'product with qualifier', :product_category => product_category, |
181 | - :enterprise_id => profile.id) | |
181 | + :profile_id => profile.id) | |
182 | 182 | img_and_qual = Product.create!(:name => 'product with image and qualifier', :product_category => product_category, |
183 | 183 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, |
184 | - :enterprise_id => profile.id) | |
184 | + :profile_id => profile.id) | |
185 | 185 | qual_only.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) |
186 | 186 | img_and_qual.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) |
187 | 187 | qual_only.save! |
... | ... | @@ -195,8 +195,8 @@ class ProductTest < ActiveSupport::TestCase |
195 | 195 | parent_cat = fast_create(ProductCategory, :name => 'Parent') |
196 | 196 | prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id) |
197 | 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 | 201 | r = Product.find_by_contents('Parent')[:results].docs |
202 | 202 | assert_includes r, p |
... | ... | @@ -206,10 +206,10 @@ class ProductTest < ActiveSupport::TestCase |
206 | 206 | should 'index by schema name when database is postgresql' do |
207 | 207 | TestSolr.enable |
208 | 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 | 210 | assert_equal [p1], Product.find_by_contents('thing')[:results].docs |
211 | 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 | 213 | assert_not_includes Product.find_by_contents('thing')[:results], p1 |
214 | 214 | assert_includes Product.find_by_contents('thing')[:results], p2 |
215 | 215 | uses_postgresql 'schema_one' |
... | ... | @@ -221,9 +221,9 @@ class ProductTest < ActiveSupport::TestCase |
221 | 221 | should 'not index by schema name when database is not postgresql' do |
222 | 222 | TestSolr.enable |
223 | 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 | 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 | 227 | assert_includes Product.find_by_contents('thing')[:results], p1 |
228 | 228 | assert_includes Product.find_by_contents('thing')[:results], p2 |
229 | 229 | end | ... | ... |
script/sample-products
... | ... | @@ -14,7 +14,7 @@ for thing in THINGS |
14 | 14 | rand(10).times do |i| |
15 | 15 | save Product.new( |
16 | 16 | :name => name, |
17 | - :enterprise_id => enterprises.rand.id, :price => (i * 13.7), | |
17 | + :profile_id => enterprises.rand.id, :price => (i * 13.7), | |
18 | 18 | :product_category_id => categories.rand.id |
19 | 19 | ) |
20 | 20 | end | ... | ... |
test/functional/catalog_controller_test.rb
... | ... | @@ -19,7 +19,7 @@ class CatalogControllerTest < ActionController::TestCase |
19 | 19 | def test_local_files_reference |
20 | 20 | assert_local_files_reference :get, :index, :profile => @enterprise.identifier |
21 | 21 | end |
22 | - | |
22 | + | |
23 | 23 | def test_valid_xhtml |
24 | 24 | assert_valid_xhtml |
25 | 25 | end |
... | ... | @@ -34,7 +34,7 @@ class CatalogControllerTest < ActionController::TestCase |
34 | 34 | get :index, :profile => 'testent' |
35 | 35 | assert_response :success |
36 | 36 | end |
37 | - | |
37 | + | |
38 | 38 | should 'list products of enterprise' do |
39 | 39 | get :index, :profile => @enterprise.identifier |
40 | 40 | assert_kind_of Array, assigns(:products) |
... | ... | @@ -42,7 +42,7 @@ class CatalogControllerTest < ActionController::TestCase |
42 | 42 | |
43 | 43 | should 'paginate enterprise products list' do |
44 | 44 | 1.upto(12).map do |
45 | - fast_create(Product, :enterprise_id => @enterprise.id) | |
45 | + fast_create(Product, :profile_id => @enterprise.id) | |
46 | 46 | end |
47 | 47 | |
48 | 48 | assert_equal 12, @enterprise.products.count |
... | ... | @@ -92,7 +92,7 @@ class CatalogControllerTest < ActionController::TestCase |
92 | 92 | end |
93 | 93 | end |
94 | 94 | |
95 | - product = fast_create(Product, :enterprise_id => @enterprise.id) | |
95 | + product = fast_create(Product, :profile_id => @enterprise.id) | |
96 | 96 | environment = Environment.default |
97 | 97 | environment.enable_plugin(Plugin1.name) |
98 | 98 | environment.enable_plugin(Plugin2.name) |
... | ... | @@ -108,10 +108,10 @@ class CatalogControllerTest < ActionController::TestCase |
108 | 108 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
109 | 109 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
110 | 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 | 116 | get :index, :profile => @enterprise.identifier, :level => pc1.id |
117 | 117 | |
... | ... | @@ -126,10 +126,10 @@ class CatalogControllerTest < ActionController::TestCase |
126 | 126 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
127 | 127 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
128 | 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 | 134 | get :index, :profile => @enterprise.identifier, :level => pc2.id |
135 | 135 | |
... | ... | @@ -140,12 +140,12 @@ class CatalogControllerTest < ActionController::TestCase |
140 | 140 | end |
141 | 141 | |
142 | 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 | 150 | get :index, :profile => @enterprise.identifier |
151 | 151 | |
... | ... | @@ -175,10 +175,10 @@ class CatalogControllerTest < ActionController::TestCase |
175 | 175 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
176 | 176 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
177 | 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 | 183 | get :index, :profile => @enterprise.identifier |
184 | 184 | |
... | ... | @@ -194,10 +194,10 @@ class CatalogControllerTest < ActionController::TestCase |
194 | 194 | pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) |
195 | 195 | pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) |
196 | 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 | 202 | get :index, :profile => @enterprise.identifier, :level => pc4.id |
203 | 203 | |
... | ... | @@ -209,8 +209,8 @@ class CatalogControllerTest < ActionController::TestCase |
209 | 209 | |
210 | 210 | should 'add product status on the class css' do |
211 | 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 | 215 | get :index, :profile => @enterprise.identifier |
216 | 216 | |
... | ... | @@ -225,10 +225,10 @@ class CatalogControllerTest < ActionController::TestCase |
225 | 225 | pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) |
226 | 226 | pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) |
227 | 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 | 233 | get :index, :profile => @enterprise.identifier |
234 | 234 | |
... | ... | @@ -236,8 +236,8 @@ class CatalogControllerTest < ActionController::TestCase |
236 | 236 | end |
237 | 237 | |
238 | 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 | 241 | Product.any_instance.stubs(:price_described?).returns(true) |
242 | 242 | production_cost = fast_create(ProductionCost) |
243 | 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 | 21 | def test_local_files_reference |
22 | 22 | assert_local_files_reference :get, :index, :profile => @enterprise.identifier |
23 | 23 | end |
24 | - | |
24 | + | |
25 | 25 | def test_valid_xhtml |
26 | 26 | assert_valid_xhtml |
27 | 27 | end |
28 | - | |
28 | + | |
29 | 29 | should "not have permission" do |
30 | 30 | u = create_user('user_test') |
31 | 31 | login_as :user_test |
... | ... | @@ -45,7 +45,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
45 | 45 | assert_response :success |
46 | 46 | assert assigns(:product) |
47 | 47 | assert_template 'new' |
48 | - assert_tag :tag => 'form', :attributes => { :action => /new/ } | |
48 | + assert_tag :tag => 'form', :attributes => { :action => /new/ } | |
49 | 49 | end |
50 | 50 | |
51 | 51 | should "create new product" do |
... | ... | @@ -66,7 +66,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
66 | 66 | end |
67 | 67 | |
68 | 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 | 70 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'name' |
71 | 71 | assert_response :success |
72 | 72 | assert assigns(:product) |
... | ... | @@ -74,7 +74,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
74 | 74 | end |
75 | 75 | |
76 | 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 | 78 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info' |
79 | 79 | assert_response :success |
80 | 80 | assert assigns(:product) |
... | ... | @@ -82,7 +82,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
82 | 82 | end |
83 | 83 | |
84 | 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 | 86 | get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'image' |
87 | 87 | assert_response :success |
88 | 88 | assert assigns(:product) |
... | ... | @@ -90,7 +90,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
90 | 90 | end |
91 | 91 | |
92 | 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 | 94 | post :edit, :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => product.id, :field => 'name' |
95 | 95 | assert_response :success |
96 | 96 | assert assigns(:product) |
... | ... | @@ -99,7 +99,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
99 | 99 | end |
100 | 100 | |
101 | 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 | 103 | post :edit, :profile => @enterprise.identifier, :product => {:description => 'A very good product!'}, :id => product.id, :field => 'info' |
104 | 104 | assert_response :success |
105 | 105 | assert assigns(:product) |
... | ... | @@ -108,7 +108,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
108 | 108 | end |
109 | 109 | |
110 | 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 | 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 | 113 | assert_response :success |
114 | 114 | assert assigns(:product) |
... | ... | @@ -117,32 +117,32 @@ class ManageProductsControllerTest < ActionController::TestCase |
117 | 117 | end |
118 | 118 | |
119 | 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 | 121 | post 'edit_category', :profile => @enterprise.identifier, :selected_category_id => nil, :id => product.id |
122 | 122 | assert_response :success |
123 | 123 | assert_template 'shared/_dialog_error_messages' |
124 | 124 | end |
125 | 125 | |
126 | 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 | 128 | assert_nothing_raised do |
129 | 129 | post 'edit_category', :profile => @enterprise.identifier, :id => product.id |
130 | 130 | end |
131 | 131 | end |
132 | 132 | |
133 | 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 | 135 | assert_difference Product, :count, -1 do |
136 | 136 | post 'destroy', :profile => @enterprise.identifier, :id => product.id |
137 | 137 | assert_response :redirect |
138 | 138 | assert_redirected_to :action => 'index' |
139 | 139 | assert assigns(:product) |
140 | 140 | assert ! Product.find_by_name('test product') |
141 | - end | |
141 | + end | |
142 | 142 | end |
143 | 143 | |
144 | 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 | 146 | Product.any_instance.stubs(:destroy).returns(false) |
147 | 147 | assert_no_difference Product, :count do |
148 | 148 | post 'destroy', :profile => @enterprise.identifier, :id => product.id |
... | ... | @@ -185,11 +185,11 @@ class ManageProductsControllerTest < ActionController::TestCase |
185 | 185 | end |
186 | 186 | |
187 | 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 | 189 | post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>" } |
190 | 190 | assert_equal "<b>descr bold</b>", assigns(:product).description |
191 | 191 | end |
192 | - | |
192 | + | |
193 | 193 | should 'not let users in if environment do not let' do |
194 | 194 | env = Environment.default |
195 | 195 | env.disable('products_for_enterprises') |
... | ... | @@ -280,14 +280,14 @@ class ManageProductsControllerTest < ActionController::TestCase |
280 | 280 | end |
281 | 281 | |
282 | 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 | 284 | get :show, :id => product.id, :profile => @enterprise.identifier |
285 | 285 | |
286 | 286 | assert_no_tag :tag => 'span', :attributes => { :class => 'product_price' }, :content => /Price:/ |
287 | 287 | end |
288 | 288 | |
289 | 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 | 291 | get :show, :id => product.id, :profile => @enterprise.identifier |
292 | 292 | |
293 | 293 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ |
... | ... | @@ -295,7 +295,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
295 | 295 | end |
296 | 296 | |
297 | 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 | 299 | get :show, :id => product.id, :profile => @enterprise.identifier |
300 | 300 | |
301 | 301 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /List price:/ |
... | ... | @@ -305,7 +305,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
305 | 305 | end |
306 | 306 | |
307 | 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 | 309 | get :show, :id => product.id, :profile => @enterprise.identifier |
310 | 310 | |
311 | 311 | assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ |
... | ... | @@ -313,7 +313,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
313 | 313 | end |
314 | 314 | |
315 | 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 | 317 | get :show, :id => product.id, :profile => @enterprise.identifier |
318 | 318 | |
319 | 319 | assert_tag :tag => 'div', :attributes => { :id => 'display-add-input-button'}, |
... | ... | @@ -321,13 +321,13 @@ class ManageProductsControllerTest < ActionController::TestCase |
321 | 321 | end |
322 | 322 | |
323 | 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 | 325 | get :show, :id => product.id, :profile => @enterprise.identifier |
326 | 326 | assert_equal [], assigns(:inputs) |
327 | 327 | end |
328 | 328 | |
329 | 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 | 331 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
332 | 332 | assert_equal [input], product.inputs |
333 | 333 | |
... | ... | @@ -337,7 +337,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
337 | 337 | end |
338 | 338 | |
339 | 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 | 341 | first = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) |
342 | 342 | second = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) |
343 | 343 | third = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) |
... | ... | @@ -358,7 +358,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
358 | 358 | should 'not list all the products of enterprise' do |
359 | 359 | @enterprise.products = [] |
360 | 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 | 362 | end |
363 | 363 | get :index, :profile => @enterprise.identifier |
364 | 364 | assert_equal 10, assigns(:products).count |
... | ... | @@ -367,7 +367,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
367 | 367 | should 'paginate the manage products list of enterprise' do |
368 | 368 | @enterprise.products = [] |
369 | 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 | 371 | end |
372 | 372 | get :index, :profile => @enterprise.identifier |
373 | 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 | 377 | end |
378 | 378 | |
379 | 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 | 381 | get :show, :id => product.id, :profile => @enterprise.identifier |
382 | 382 | |
383 | 383 | assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } |
... | ... | @@ -388,7 +388,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
388 | 388 | |
389 | 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 | 392 | get :show, :id => product.id, :profile => @enterprise.identifier |
393 | 393 | |
394 | 394 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } |
... | ... | @@ -397,7 +397,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
397 | 397 | should 'not display tabs if description and inputs are empty and user is not logged in' do |
398 | 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 | 401 | get :show, :id => product.id, :profile => @enterprise.identifier |
402 | 402 | |
403 | 403 | assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } |
... | ... | @@ -407,7 +407,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
407 | 407 | create_user('foo') |
408 | 408 | |
409 | 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 | 411 | get :show, :id => product.id, :profile => @enterprise.identifier |
412 | 412 | assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#product-description'}, :content => 'Description'} |
413 | 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 | 417 | create_user 'foo' |
418 | 418 | |
419 | 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 | 421 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
422 | 422 | |
423 | 423 | get :show, :id => product.id, :profile => @enterprise.identifier |
... | ... | @@ -429,7 +429,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
429 | 429 | create_user('foo') |
430 | 430 | |
431 | 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 | 433 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
434 | 434 | |
435 | 435 | get :show, :id => product.id, :profile => @enterprise.identifier |
... | ... | @@ -449,7 +449,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
449 | 449 | end |
450 | 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 | 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 | 471 | end |
472 | 472 | |
473 | 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 | 475 | cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'Environment') |
476 | 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 | 18 | |
19 | 19 | should 'find product to show' do |
20 | 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 | 23 | assert_equal prod, assigns(:product) |
24 | 24 | end |
25 | 25 | |
26 | 26 | should 'find person to show' do |
27 | 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 | 29 | assert_equal pers, assigns(:profile) |
30 | 30 | end |
31 | 31 | |
32 | 32 | should 'find enterprise to show' do |
33 | 33 | ent = Enterprise.create!(:name => 'Enterprise1', :identifier => 'ent1') |
34 | - get :enterprise, :id => ent.id | |
34 | + get :enterprise, :id => ent.id | |
35 | 35 | assert_equal ent, assigns(:profile) |
36 | 36 | end |
37 | 37 | |
38 | 38 | should 'find community to show' do |
39 | 39 | comm = Community.create!(:name => 'Community1', :identifier => 'comm1') |
40 | - get :community, :id => comm.id | |
40 | + get :community, :id => comm.id | |
41 | 41 | assert_equal comm, assigns(:profile) |
42 | 42 | end |
43 | 43 | end | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -166,7 +166,7 @@ class SearchControllerTest < ActionController::TestCase |
166 | 166 | |
167 | 167 | enterprise = fast_create(Enterprise) |
168 | 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 | 171 | e = Environment.default |
172 | 172 | e.enable_plugin(Plugin1.name) |
... | ... | @@ -191,7 +191,7 @@ class SearchControllerTest < ActionController::TestCase |
191 | 191 | end |
192 | 192 | enterprise = fast_create(Enterprise) |
193 | 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 | 196 | environment = Environment.default |
197 | 197 | environment.enable_plugin(Plugin1.name) |
... | ... | @@ -348,15 +348,15 @@ class SearchControllerTest < ActionController::TestCase |
348 | 348 | should 'show events for current month by default' do |
349 | 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 | 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 | 354 | :start_date => Date.today + 2.day) |
355 | 355 | |
356 | 356 | get :events |
357 | 357 | |
358 | 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 | 360 | end |
361 | 361 | |
362 | 362 | should 'list events for a given month' do |
... | ... | @@ -394,7 +394,7 @@ class SearchControllerTest < ActionController::TestCase |
394 | 394 | prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) |
395 | 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 | 399 | get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id |
400 | 400 | |
... | ... | @@ -590,7 +590,7 @@ class SearchControllerTest < ActionController::TestCase |
590 | 590 | a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) |
591 | 591 | a.tag_list = ['one', 'two'] |
592 | 592 | a.save_tags |
593 | - | |
593 | + | |
594 | 594 | get :tags |
595 | 595 | |
596 | 596 | assert assigns(:tags)["two"] = 1 |
... | ... | @@ -605,7 +605,7 @@ class SearchControllerTest < ActionController::TestCase |
605 | 605 | a2.tag_list = ['two', 'three'] |
606 | 606 | a.save_tags |
607 | 607 | a2.save_tags |
608 | - | |
608 | + | |
609 | 609 | get :tag, :tag => 'two' |
610 | 610 | |
611 | 611 | assert_equivalent [a, a2], assigns(:searches)[:tag][:results] |
... | ... | @@ -621,7 +621,7 @@ class SearchControllerTest < ActionController::TestCase |
621 | 621 | p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) |
622 | 622 | art1 = Article.create!(:name => 'my article', :profile_id => p1.id) |
623 | 623 | art2 = Article.create!(:name => 'my article', :profile_id => p2.id) |
624 | - | |
624 | + | |
625 | 625 | get :articles, :query => 'my article' |
626 | 626 | |
627 | 627 | assert_equal [art2], assigns(:searches)[:articles][:results] |
... | ... | @@ -632,22 +632,22 @@ class SearchControllerTest < ActionController::TestCase |
632 | 632 | art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) |
633 | 633 | art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now) |
634 | 634 | art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) |
635 | - | |
635 | + | |
636 | 636 | get :articles, :filter => :more_recent |
637 | 637 | |
638 | 638 | assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results] |
639 | 639 | end |
640 | - | |
640 | + | |
641 | 641 | should 'add highlighted CSS class around a highlighted product' do |
642 | 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 | 644 | get :products |
645 | 645 | assert_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Enter Sandman/ |
646 | 646 | end |
647 | 647 | |
648 | 648 | should 'do not add highlighted CSS class around an ordinary product' do |
649 | 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 | 651 | get :products |
652 | 652 | assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Holier Than Thou/ |
653 | 653 | end | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -393,13 +393,13 @@ class EnterpriseTest < ActiveSupport::TestCase |
393 | 393 | p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => @product_category.id) |
394 | 394 | products = [] |
395 | 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 | 397 | :highlighted => true, :product_category_id => @product_category.id, |
398 | 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 | 403 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
404 | 404 | }) |
405 | 405 | assert_equal products, e1.highlighted_products_with_image |
... | ... | @@ -407,7 +407,7 @@ class EnterpriseTest < ActiveSupport::TestCase |
407 | 407 | |
408 | 408 | should 'has many inputs through products' do |
409 | 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 | 411 | product.inputs << Input.new(:product_category => @product_category) |
412 | 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 | 384 | p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) |
385 | 385 | products = [] |
386 | 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 | 388 | :product_category_id => category.id, :highlighted => true, |
389 | 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 | 394 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
395 | 395 | }) |
396 | 396 | assert_equal products, env.highlighted_products_with_image |
... | ... | @@ -718,7 +718,7 @@ class EnvironmentTest < ActiveSupport::TestCase |
718 | 718 | assert_equal c, e.portal_community |
719 | 719 | e.unset_portal_community! |
720 | 720 | e.reload |
721 | - assert_nil e.portal_community | |
721 | + assert_nil e.portal_community | |
722 | 722 | assert_equal [], e.portal_folders |
723 | 723 | assert_equal 0, e.news_amount_by_folder |
724 | 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 | 13 | profile = fast_create(Enterprise) |
14 | 14 | products = [] |
15 | 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 | 17 | featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id)) |
18 | 18 | assert_equal products, featured_products_block.products |
19 | 19 | end |
... | ... | @@ -66,7 +66,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
66 | 66 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
67 | 67 | category = fast_create(ProductCategory) |
68 | 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 | 70 | :highlighted => true, :product_category_id => category.id, |
71 | 71 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } |
72 | 72 | ) |
... | ... | @@ -82,7 +82,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
82 | 82 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
83 | 83 | category = fast_create(ProductCategory) |
84 | 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 | 87 | @environment.boxes.first.blocks<< block |
88 | 88 | |
... | ... | @@ -95,7 +95,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
95 | 95 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
96 | 96 | category = fast_create(ProductCategory) |
97 | 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 | 99 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
100 | 100 | }) |
101 | 101 | } |
... | ... | @@ -118,13 +118,13 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
118 | 118 | category = fast_create(ProductCategory) |
119 | 119 | products = [] |
120 | 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 | 122 | :highlighted => true, :product_category_id => category.id, |
123 | 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 | 128 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
129 | 129 | }) |
130 | 130 | @environment.boxes.first.blocks<< block | ... | ... |
test/unit/input_test.rb
... | ... | @@ -115,7 +115,7 @@ class InputTest < ActiveSupport::TestCase |
115 | 115 | should 'display amount used' do |
116 | 116 | ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') |
117 | 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 | 120 | input = Input.new(:product => product) |
121 | 121 | input.amount_used = 10.45 |
... | ... | @@ -134,7 +134,7 @@ class InputTest < ActiveSupport::TestCase |
134 | 134 | should 'display only integer value if decimal value is 00' do |
135 | 135 | ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') |
136 | 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 | 139 | input = Input.new(:product => product) |
140 | 140 | input.amount_used = 10.00 |
... | ... | @@ -144,7 +144,7 @@ class InputTest < ActiveSupport::TestCase |
144 | 144 | should 'display formatted value' do |
145 | 145 | ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') |
146 | 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 | 149 | input = Input.new(:product => product) |
150 | 150 | input.price_per_unit = 1.45 | ... | ... |
test/unit/price_detail_test.rb
... | ... | @@ -70,7 +70,7 @@ class PriceDetailTest < ActiveSupport::TestCase |
70 | 70 | |
71 | 71 | should 'format values to float with 2 decimals' do |
72 | 72 | enterprise = fast_create(Enterprise) |
73 | - product = fast_create(Product, :enterprise_id => enterprise.id) | |
73 | + product = fast_create(Product, :profile_id => enterprise.id) | |
74 | 74 | cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'environment') |
75 | 75 | |
76 | 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 | 7 | assert_equivalent [], c0.all_products |
8 | 8 | |
9 | 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 | 11 | c0.reload |
12 | 12 | assert_equivalent [p0], c0.all_products |
13 | 13 | |
14 | 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 | 16 | c0.reload; c1.reload |
17 | 17 | assert_equivalent [p0, p1], c0.all_products |
18 | 18 | assert_equivalent [p1], c1.all_products | ... | ... |
test/unit/product_test.rb
... | ... | @@ -18,14 +18,14 @@ class ProductTest < ActiveSupport::TestCase |
18 | 18 | should 'return associated enterprise region' do |
19 | 19 | @profile.region = fast_create Region, :name => 'Salvador' |
20 | 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 | 23 | assert_equal @profile.region, p.region |
24 | 24 | end |
25 | 25 | |
26 | 26 | should 'create product' do |
27 | 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 | 29 | assert p.save |
30 | 30 | end |
31 | 31 | end |
... | ... | @@ -84,7 +84,7 @@ class ProductTest < ActiveSupport::TestCase |
84 | 84 | assert_difference Product, :count do |
85 | 85 | p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { |
86 | 86 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
87 | - }, :enterprise_id => @profile.id) | |
87 | + }, :profile_id => @profile.id) | |
88 | 88 | assert_equal p.image(true).filename, 'rails.png' |
89 | 89 | end |
90 | 90 | end |
... | ... | @@ -138,7 +138,7 @@ class ProductTest < ActiveSupport::TestCase |
138 | 138 | |
139 | 139 | should 'respond to public? as its enterprise public?' do |
140 | 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 | 143 | assert p1.public? |
144 | 144 | |
... | ... | @@ -197,7 +197,7 @@ class ProductTest < ActiveSupport::TestCase |
197 | 197 | end |
198 | 198 | |
199 | 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 | 201 | assert product.valid? |
202 | 202 | assert_equal product.name, @product_category.name |
203 | 203 | end |
... | ... | @@ -217,7 +217,7 @@ class ProductTest < ActiveSupport::TestCase |
217 | 217 | |
218 | 218 | should 'format values to float with 2 decimals' do |
219 | 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 | 222 | assert_equal "12.99", product.formatted_value(:price) |
223 | 223 | assert_equal "1.99", product.formatted_value(:discount) |
... | ... | @@ -225,14 +225,14 @@ class ProductTest < ActiveSupport::TestCase |
225 | 225 | |
226 | 226 | should 'calculate price with discount' do |
227 | 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 | 230 | assert_equal 11.00, product.price_with_discount |
231 | 231 | end |
232 | 232 | |
233 | 233 | should 'calculate price without discount' do |
234 | 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 | 237 | assert_equal product.price, product.price_with_discount |
238 | 238 | end |
... | ... | @@ -254,7 +254,7 @@ class ProductTest < ActiveSupport::TestCase |
254 | 254 | |
255 | 255 | should 'return product inputs' do |
256 | 256 | ent = fast_create(Enterprise) |
257 | - product = fast_create(Product, :enterprise_id => ent.id) | |
257 | + product = fast_create(Product, :profile_id => ent.id) | |
258 | 258 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
259 | 259 | |
260 | 260 | assert_equal [input], product.inputs |
... | ... | @@ -262,7 +262,7 @@ class ProductTest < ActiveSupport::TestCase |
262 | 262 | |
263 | 263 | should 'destroy inputs when product is removed' do |
264 | 264 | ent = fast_create(Enterprise) |
265 | - product = fast_create(Product, :enterprise_id => ent.id) | |
265 | + product = fast_create(Product, :profile_id => ent.id) | |
266 | 266 | input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) |
267 | 267 | |
268 | 268 | services_category = fast_create(ProductCategory, :name => 'Services') |
... | ... | @@ -414,7 +414,7 @@ class ProductTest < ActiveSupport::TestCase |
414 | 414 | |
415 | 415 | should 'return production costs from enterprise and environment' do |
416 | 416 | ent = fast_create(Enterprise) |
417 | - product = fast_create(Product, :enterprise_id => ent.id) | |
417 | + product = fast_create(Product, :profile_id => ent.id) | |
418 | 418 | ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile') |
419 | 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 | 423 | |
424 | 424 | should 'return all production costs' do |
425 | 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 | 428 | env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') |
429 | 429 | ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile') |
... | ... | @@ -433,7 +433,7 @@ class ProductTest < ActiveSupport::TestCase |
433 | 433 | |
434 | 434 | should 'return total value of production costs' do |
435 | 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 | 438 | env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') |
439 | 439 | price_detail = product.price_details.create(:production_cost => env_production_cost, :price => 10) |
... | ... | @@ -445,7 +445,7 @@ class ProductTest < ActiveSupport::TestCase |
445 | 445 | |
446 | 446 | should 'return inputs cost as total value of production costs if has no price details' do |
447 | 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 | 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 | 460 | |
461 | 461 | should 'format inputs cost values to float with 2 decimals' do |
462 | 462 | ent = fast_create(Enterprise) |
463 | - product = fast_create(Product, :enterprise_id => ent.id) | |
463 | + product = fast_create(Product, :profile_id => ent.id) | |
464 | 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 | 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 | 490 | end |
491 | 491 | |
492 | 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 | 494 | assert_equal 0, prod.percentage_from_solidarity_economy.first |
495 | 495 | |
496 | 496 | Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, |
... | ... | @@ -505,7 +505,7 @@ class ProductTest < ActiveSupport::TestCase |
505 | 505 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) |
506 | 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 | 509 | Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, |
510 | 510 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) |
511 | 511 | Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, |
... | ... | @@ -516,7 +516,7 @@ class ProductTest < ActiveSupport::TestCase |
516 | 516 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) |
517 | 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 | 520 | Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, |
521 | 521 | :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) |
522 | 522 | assert_equal 100, prod.percentage_from_solidarity_economy.first |
... | ... | @@ -526,7 +526,7 @@ class ProductTest < ActiveSupport::TestCase |
526 | 526 | enterprise = fast_create(Enterprise) |
527 | 527 | Enterprise.any_instance.expects(:region) |
528 | 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 | 530 | product.region |
531 | 531 | product.region_id |
532 | 532 | end |
... | ... | @@ -535,7 +535,7 @@ class ProductTest < ActiveSupport::TestCase |
535 | 535 | enterprise = fast_create(Enterprise) |
536 | 536 | Enterprise.any_instance.expects(:environment) |
537 | 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 | 539 | product.environment |
540 | 540 | product.environment_id |
541 | 541 | end |
... | ... | @@ -543,9 +543,9 @@ class ProductTest < ActiveSupport::TestCase |
543 | 543 | should 'return more recent products' do |
544 | 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 | 550 | prod1.update_attribute :created_at, Time.now-2.days |
551 | 551 | prod2.update_attribute :created_at, Time.now-1.days |
... | ... | @@ -579,9 +579,9 @@ class ProductTest < ActiveSupport::TestCase |
579 | 579 | |
580 | 580 | should 'return from_category scope untouched if passed nil' do |
581 | 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 | 586 | products = enterprise.products.from_category(nil) |
587 | 587 | ... | ... |