Commit aedeaf613bd70f5356e06f224c035c427026cb4a
1 parent
0dc6f123
Exists in
master
and in
29 other branches
New interface to select category of products
- Old interface for category selection was removed - Allow nil for product name - Procuct category is mandatory for new products - Optimizing some functional tests - Categories have attribute to set if accept or no products (ActionItem1391)
Showing
44 changed files
with
947 additions
and
624 deletions
Show diff stats
app/controllers/my_profile/manage_products_controller.rb
... | ... | @@ -22,23 +22,36 @@ class ManageProductsController < ApplicationController |
22 | 22 | @product = @profile.products.find(params[:id]) |
23 | 23 | end |
24 | 24 | |
25 | + def categories_for_selection | |
26 | + @category = Category.find(params[:category_id]) if params[:category_id] | |
27 | + if @category | |
28 | + @categories = @category.children | |
29 | + @level = @category.leaf? ? @category.level : @categories.first.level | |
30 | + else | |
31 | + @categories = ProductCategory.top_level_for(environment) | |
32 | + @level = 0 | |
33 | + end | |
34 | + render :partial => 'categories_for_selection' | |
35 | + end | |
36 | + | |
25 | 37 | def new |
26 | - @object = Product.new | |
27 | - @categories = @current_category.nil? ? ProductCategory.top_level_for(environment) : @current_category.children | |
28 | 38 | @product = @profile.products.build(params[:product]) |
39 | + @category = @product.product_category | |
40 | + @categories = ProductCategory.top_level_for(environment) | |
41 | + @level = 0 | |
29 | 42 | if request.post? |
30 | 43 | if @product.save |
31 | 44 | flash[:notice] = _('Product succesfully created') |
32 | - redirect_to :action => 'show', :id => @product | |
45 | + render :partial => 'shared/redirect_via_javascript', | |
46 | + :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } | |
33 | 47 | else |
34 | - flash[:notice] = _('Could not create the product') | |
48 | + render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } | |
35 | 49 | end |
36 | 50 | end |
37 | 51 | end |
38 | 52 | |
39 | 53 | def edit |
40 | - @product = @profile.products.find(params[:id]) | |
41 | - @object = @profile.products.find(params[:id]) | |
54 | + @object = @product = @profile.products.find(params[:id]) | |
42 | 55 | @current_category = @product.product_category |
43 | 56 | @categories = @current_category.nil? ? [] : @current_category.children |
44 | 57 | if request.post? |
... | ... | @@ -62,56 +75,4 @@ class ManageProductsController < ApplicationController |
62 | 75 | end |
63 | 76 | end |
64 | 77 | |
65 | - def update_categories | |
66 | - @object = params[:id] ? @profile.products.find(params[:id]) : Product.new | |
67 | - if params[:category_id] | |
68 | - @current_category = Category.find(params[:category_id]) | |
69 | - @categories = @current_category.children | |
70 | - else | |
71 | - @current_category = ProductCategory.top_level_for(environment).first | |
72 | - @categories = @current_category.nil? ? [] : @current_category.children | |
73 | - end | |
74 | - render :partial => 'shared/select_categories', :locals => {:object_name => 'product', :multiple => false}, :layout => false | |
75 | - end | |
76 | - | |
77 | - def update_subcategories | |
78 | - @current_category = ProductCategory.find(params[:id]) if params[:id] | |
79 | - @categories = @current_category ? @current_category.children : ProductCategory.top_level_for(environment) | |
80 | - render :partial => 'subcategories' | |
81 | - end | |
82 | - | |
83 | - def new_consumption | |
84 | - @consumption = @profile.consumptions.build(params[:consumption]) | |
85 | - if request.post? | |
86 | - if @consumption.save | |
87 | - flash[:notice] = _('Raw material succesfully created') | |
88 | - redirect_to :action => 'index' | |
89 | - else | |
90 | - flash[:notice] = _('Could not create the raw material') | |
91 | - end | |
92 | - end | |
93 | - end | |
94 | - | |
95 | - def destroy_consumption | |
96 | - @consumption = @profile.consumptions.find(params[:id]) | |
97 | - if @consumption.destroy | |
98 | - flash[:notice] = _('Raw material succesfully removed') | |
99 | - else | |
100 | - flash[:notice] = _('Could not remove the raw material') | |
101 | - end | |
102 | - redirect_back_or_default :action => 'index' | |
103 | - end | |
104 | - | |
105 | - def edit_consumption | |
106 | - @consumption = @profile.consumptions.find(params[:id]) | |
107 | - if request.post? | |
108 | - if @consumption.update_attributes(params[:consumption]) | |
109 | - flash[:notice] = _('Raw material succesfully updated') | |
110 | - redirect_back_or_default :action => 'index' | |
111 | - else | |
112 | - flash[:notice] = _('Could not update the raw material') | |
113 | - end | |
114 | - end | |
115 | - end | |
116 | - | |
117 | 78 | end | ... | ... |
app/helpers/manage_products_helper.rb
1 | 1 | module ManageProductsHelper |
2 | + | |
3 | + def remote_function_to_update_categories_selection(container_id, options = {}) | |
4 | + remote_function({ | |
5 | + :update => container_id, | |
6 | + :url => { :action => "categories_for_selection" }, | |
7 | + :loading => "loading('hierarchy_navigation', '#{ _('loading…') }'); loading('#{container_id}', ' ')", | |
8 | + :complete => "loading_done('hierarchy_navigation'); loading_done('#{container_id}')" | |
9 | + }.merge(options)) | |
10 | + end | |
11 | + | |
12 | + def hierarchy_category_item(category, make_links, title = nil) | |
13 | + title ||= category.name | |
14 | + if make_links | |
15 | + link_to(title, '#', | |
16 | + :title => title, | |
17 | + :onclick => remote_function_to_update_categories_selection("categories_container_level#{ category.level + 1 }", | |
18 | + :with => "'category_id=#{ category.id }'" | |
19 | + ) | |
20 | + ) | |
21 | + else | |
22 | + title | |
23 | + end | |
24 | + end | |
25 | + | |
26 | + def hierarchy_category_navigation(current_category, options = {}) | |
27 | + hierarchy = [] | |
28 | + if current_category | |
29 | + hierarchy << current_category.name | |
30 | + count_chars = current_category.name.length | |
31 | + ancestors = current_category.ancestors | |
32 | + toplevel = ancestors.pop | |
33 | + if toplevel | |
34 | + count_chars += toplevel.name.length | |
35 | + end | |
36 | + ancestors.each do |category| | |
37 | + if count_chars > 60 | |
38 | + hierarchy << hierarchy_category_item(category, options[:make_links], '( … )') | |
39 | + break | |
40 | + else | |
41 | + hierarchy << hierarchy_category_item(category, options[:make_links]) | |
42 | + end | |
43 | + count_chars += category.name.length | |
44 | + end | |
45 | + if toplevel | |
46 | + hierarchy << hierarchy_category_item(toplevel, options[:make_links]) | |
47 | + end | |
48 | + end | |
49 | + hierarchy.reverse.join(options[:separator] || ' → ') | |
50 | + end | |
51 | + | |
52 | + def options_for_select_categories(categories) | |
53 | + categories.sort_by{|cat| cat.name.transliterate}.map do |category| | |
54 | + "<option value='#{category.id}'>#{category.name + (category.leaf? ? '': ' »')}</option>" | |
55 | + end.join("\n") | |
56 | + end | |
57 | + | |
58 | + def select_for_categories(categories, level = 0) | |
59 | + if categories.empty? | |
60 | + content_tag('div', '', :id => 'no_subcategories') | |
61 | + else | |
62 | + select_tag('category_id', | |
63 | + options_for_select_categories(categories), | |
64 | + :size => 10, | |
65 | + :onchange => remote_function_to_update_categories_selection("categories_container_level#{ level + 1 }", :with => "'category_id=' + this.value") | |
66 | + ) + | |
67 | + content_tag('div', '', :class => 'categories_container', :id => "categories_container_level#{ level + 1 }") | |
68 | + end | |
69 | + end | |
70 | + | |
2 | 71 | end | ... | ... |
app/models/product.rb
... | ... | @@ -3,8 +3,8 @@ class Product < ActiveRecord::Base |
3 | 3 | belongs_to :product_category |
4 | 4 | has_many :product_categorizations |
5 | 5 | |
6 | - validates_presence_of :name | |
7 | - validates_uniqueness_of :name, :scope => :enterprise_id | |
6 | + validates_uniqueness_of :name, :scope => :enterprise_id, :allow_nil => true | |
7 | + validates_presence_of :product_category | |
8 | 8 | validates_numericality_of :price, :allow_nil => true |
9 | 9 | |
10 | 10 | after_update :save_image | ... | ... |
app/views/manage_products/_categories_for_selection.rhtml
0 → 100644
... | ... | @@ -0,0 +1,8 @@ |
1 | +<%= select_for_categories(@categories, @level) %> | |
2 | + | |
3 | +<% javascript_tag do %> | |
4 | + jQuery('#categories_container_wrapper').scrollTo('100%', 1000) | |
5 | + $('product_product_category_id').value = <%= @category && @category.id %> | |
6 | + $('hierarchy_navigation').update('<%= escape_javascript(hierarchy_category_navigation(@category, :make_links => true)) %>') | |
7 | + toggleDisabled(<%= @category && @category.accept_products? ? 'true' : 'false' %>, $('save_and_continue')) | |
8 | +<% end %> | ... | ... |
app/views/manage_products/_form.rhtml
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | <% form_for :product, @product, :html => {:multipart => true }, :url => {:action => mode} do |f| %> |
4 | 4 | <%= required_fields_message %> |
5 | 5 | |
6 | - <%= required display_form_field( _('Name:'), f.text_field(:name) ) %> | |
6 | + <%= display_form_field( _('Name:'), f.text_field(:name) ) %> | |
7 | 7 | <%= display_form_field( _('Price:'), f.text_field(:price) ) %> |
8 | 8 | <%= display_form_field( _('Description:'), f.text_area(:description, :rows => 10) ) %> |
9 | 9 | <%= labelled_form_field(f.check_box(:highlighted) + _('Highlight this product'),'') %> |
... | ... | @@ -11,10 +11,6 @@ |
11 | 11 | <%= file_field_or_thumbnail(_('Image:'), @product.image, i) %> |
12 | 12 | <% end %> |
13 | 13 | |
14 | - <div id='subcategories'> | |
15 | - <%= render :partial => 'subcategories' %> | |
16 | - </div> | |
17 | - | |
18 | 14 | <% button_bar do %> |
19 | 15 | <%= submit_button('save', (mode == 'new' ? _('Create product') : _('Save changes')), :cancel => {:action => 'index'} ) %> |
20 | 16 | <% end %> | ... | ... |
app/views/manage_products/_form_consumption.rhtml
... | ... | @@ -1,9 +0,0 @@ |
1 | -<%= error_messages_for :consumption %> <br/> | |
2 | - | |
3 | -<% form_for :consumption, @consumption, nil, :url => {:action => action} do |f| %> | |
4 | - <%= display_form_field( _('Raw material:'), f.select("product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]}) ) if action == 'new_consumption' %> | |
5 | - <%= display_form_field( _('Aditional specifications:'), f.text_area("aditional_specifications", :rows => 5) ) %> | |
6 | - <% button_bar do %> | |
7 | - <%= submit_button('save', (action == 'new_consumption' ? _('Add raw material') : _('Save changes')), :cancel => {:action => 'index'} ) %> | |
8 | - <% end %> | |
9 | -<% end %> |
app/views/manage_products/_subcategories.rhtml
... | ... | @@ -1,31 +0,0 @@ |
1 | -<% if !@current_category.nil? %> | |
2 | - | |
3 | - <p><%= _('Current category:') %></p> | |
4 | - <%= hidden_field_tag 'product[product_category_id]', @current_category.id %> | |
5 | - <%= link_to_remote( _('Back'), | |
6 | - :update => "subcategories", | |
7 | - :url => { :action => 'update_subcategories', :id => nil, :loaded => visual_effect(:highlight, "subcategories") }, | |
8 | - :class => 'select-current-category-link') + ' → ' | |
9 | - %> | |
10 | - <%= ([@current_category] + @current_category.ancestors).reverse.map{|i| | |
11 | - link_to_remote(i.name, | |
12 | - :update => "subcategories", | |
13 | - :url => { :action => 'update_subcategories', :id => i, :loaded => visual_effect(:highlight, "subcategories") }, | |
14 | - :class => 'select-current-category-link')}.join(' → ') | |
15 | - %> | |
16 | -<% end %> | |
17 | - | |
18 | -<% if @current_category.nil? %> | |
19 | - <p><%= _('Select a category:') %></p> | |
20 | -<% elsif !@categories.empty? %> | |
21 | - <p><%= _('Select a subcategory:') %></p> | |
22 | -<% end %> | |
23 | - | |
24 | -<% for category in @categories do %> | |
25 | - <%= link_to_remote category.name, { | |
26 | - :update => "subcategories", | |
27 | - :url => { :action => "update_subcategories", :id => category.id }, | |
28 | - :loaded => visual_effect(:highlight, "subcategories") }, | |
29 | - :class => 'select-subcategory-link' | |
30 | - %> | |
31 | -<% end %> |
app/views/manage_products/edit_consumption.rhtml
app/views/manage_products/index.rhtml
... | ... | @@ -27,39 +27,3 @@ |
27 | 27 | <%= button :add, _('New product or service'), :action => 'new' %> |
28 | 28 | <%= button :back, _('Back'), { :controller => 'profile_editor', :profile => @profile.identifier, :action => 'index' } %> |
29 | 29 | <% end %> |
30 | - | |
31 | -<br /> | |
32 | - | |
33 | -<h3> <%=_('Listing raw materials') %> </h3> | |
34 | - | |
35 | -<table> | |
36 | - <tr> | |
37 | - <th><%= _('Raw material') %></th> | |
38 | - <th><%= _('Actions') %></th> | |
39 | - </tr> | |
40 | - <% if @consumptions.empty? %> | |
41 | - <tr> | |
42 | - <td colspan='3' style='text-align: center; padding: 10px'><em><%= _('(no raw material registered yet)') %></em></td> | |
43 | - </tr> | |
44 | - <% end %> | |
45 | - <% @consumptions.each do |consumption| %> | |
46 | - <tr> | |
47 | - <td> | |
48 | - <strong><%= link_to_product_category(consumption.product_category) %></strong> | |
49 | - <br/> | |
50 | - <em><%= consumption.aditional_specifications %></em> | |
51 | - </td> | |
52 | - <td> | |
53 | - <%= button :edit, _('Edit'), :action => 'edit_consumption', :id => consumption %> | |
54 | - <%= button :delete, _('Remove'), { :action => 'destroy_consumption', :id => consumption }, :confirm => _('Are you sure, you want to remove this raw material from your list') %> | |
55 | - </td> | |
56 | - </tr> | |
57 | - <% end %> | |
58 | -</table> | |
59 | - | |
60 | -<% button_bar do %> | |
61 | - <%= button :add, _('Add raw material'), :action => 'new_consumption' %> | |
62 | - <%= button :back, _('Back'), { :controller => 'profile_editor', :profile => @profile.identifier, :action => 'index' } %> | |
63 | -<% end %> | |
64 | - | |
65 | - | ... | ... |
app/views/manage_products/new.rhtml
1 | -<h2> <%= _('New product') %> </h2> | |
1 | +<h2 id='new_product_title'><%= _('New product or service') %></h2> | |
2 | 2 | |
3 | -<%= render :partial => 'form', :locals => {:mode => 'new'} %> | |
3 | +<div id='request_result_message' style='display: none'></div> | |
4 | + | |
5 | +<% remote_form_for :product, @product, | |
6 | + :loading => "open_loading('#{ _('loading...') }')", | |
7 | + :update => "request_result_message", | |
8 | + :url => {:action => 'new'}, | |
9 | + :html => {:method => 'post', :id => 'new_product_form'} do |f| %> | |
10 | + | |
11 | + <h3><%= _('Select the category of the new product or service') %></h3> | |
12 | + | |
13 | + <%= f.hidden_field 'product_category_id' %> | |
14 | + | |
15 | + <div id='hierarchy_navigation'> </div> | |
16 | + | |
17 | + <div id='categories_container_wrapper'> | |
18 | + <div class='categories_container' id='categories_container_level0'> | |
19 | + <%= render :partial => 'categories_for_selection' %> | |
20 | + </div> | |
21 | + </div> | |
22 | + | |
23 | + <div id='categories_selection_actionbar'> | |
24 | + <%= button :back, _('Back to the product listing'), :action => 'index' %> | |
25 | + <span id='save_and_continue_wrapper'> | |
26 | + <%= submit_button(:save, _('Save and continue'), :id => 'save_and_continue') %> | |
27 | + <span class='tooltip' id='save_and_continue_disabled_tooltip'> | |
28 | + <%= ui_icon(:alert) %> | |
29 | + <%= _('This category does not allow registration of products, select a more specific category') %> | |
30 | + </span> | |
31 | + </span> | |
32 | + </div> | |
33 | + | |
34 | +<% end %> | |
35 | + | |
36 | +<% javascript_tag do %> | |
37 | + toggleDisabled(<%= @category && @category.accept_products? ? 'true' : 'false' %>, $('save_and_continue')) | |
38 | +<% end %> | ... | ... |
app/views/manage_products/new_consumption.rhtml
app/views/manage_products/show.rhtml
... | ... | @@ -5,8 +5,8 @@ |
5 | 5 | <p> <strong><%= _('Description:') %></strong> <%= txt2html @product.description if @product.description %> </p> |
6 | 6 | <p> <strong><%= _('Category:') %></strong> <%= link_to_product_category(@product.product_category) %> </p> |
7 | 7 | |
8 | -<%= button :back, _('back'), :action => 'index' %> | |
8 | +<%= button :back, _('Back'), :action => 'index' %> | |
9 | 9 | |
10 | -<%= button :delete, _('destroy'), :action => 'destroy', :id => @product %> | |
11 | -<%= button :edit, _('edit'), :action => 'edit', :id => @product %> | |
10 | +<%= button :delete, _('Destroy'), :action => 'destroy', :id => @product %> | |
11 | +<%= button :edit, _('Edit'), :action => 'edit', :id => @product %> | |
12 | 12 | ... | ... |
db/migrate/20100617195958_add_accept_products_to_categories.rb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +class AddAcceptProductsToCategories < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + add_column :categories, :accept_products, :boolean, :default => true | |
4 | + execute 'UPDATE categories SET accept_products = (1 > 0)' | |
5 | + end | |
6 | + | |
7 | + def self.down | |
8 | + remove_column :categories, :accept_products | |
9 | + end | |
10 | +end | ... | ... |
db/migrate/20100621235235_set_product_category_id_to_products.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class SetProductCategoryIdToProducts < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + Product.all(:conditions => { :product_category_id => nil }).each do |product| | |
4 | + next if product.enterprise.nil? | |
5 | + product.product_category = ProductCategory.top_level_for(product.enterprise.environment).first | |
6 | + product.save! | |
7 | + end | |
8 | + end | |
9 | + | |
10 | + def self.down | |
11 | + say "WARNING: cannot undo this migration" | |
12 | + end | |
13 | +end | ... | ... |
db/schema.rb
... | ... | @@ -9,8 +9,7 @@ |
9 | 9 | # |
10 | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | |
12 | - | |
13 | -ActiveRecord::Schema.define(:version => 20100619031945) do | |
12 | +ActiveRecord::Schema.define(:version => 20100621235235) do | |
14 | 13 | |
15 | 14 | create_table "article_versions", :force => true do |t| |
16 | 15 | t.integer "article_id" |
... | ... | @@ -130,6 +129,7 @@ ActiveRecord::Schema.define(:version => 20100619031945) do |
130 | 129 | t.float "lng" |
131 | 130 | t.boolean "display_in_menu", :default => false |
132 | 131 | t.integer "children_count", :default => 0 |
132 | + t.boolean "accept_products", :default => true | |
133 | 133 | end |
134 | 134 | |
135 | 135 | create_table "categories_profiles", :id => false, :force => true do |t| | ... | ... |
... | ... | @@ -0,0 +1,136 @@ |
1 | +Feature: manage products | |
2 | + As an enterprise owner | |
3 | + I want to manage my products | |
4 | + | |
5 | + Background: | |
6 | + Given the following users | |
7 | + | login | name | | |
8 | + | joaosilva | Joao Silva | | |
9 | + And the following enterprises | |
10 | + | identifier | owner | name | enabled | | |
11 | + | redemoinho | joaosilva | Rede Moinho | true | | |
12 | + And feature "disable_products_for_enterprises" is disabled on environment | |
13 | + And I am logged in as "joaosilva" | |
14 | + And I am on Rede Moinho's control panel | |
15 | + And I follow "Manage Products and Services" | |
16 | + | |
17 | + Scenario: listing products and services | |
18 | + Then I should see "Listing products and services" | |
19 | + | |
20 | + Scenario: see toplevel categories | |
21 | + Given the following product_categories | |
22 | + | name | | |
23 | + | Products | | |
24 | + | Services | | |
25 | + When I follow "New product or service" | |
26 | + Then I should see "Products" | |
27 | + And I should see "Service" | |
28 | + | |
29 | + @selenium | |
30 | + Scenario: select a toplevel category and see subcategories | |
31 | + Given the following product_categories | |
32 | + | name | | |
33 | + | Products level0 | | |
34 | + And the following product_categories | |
35 | + | name | parent | | |
36 | + | Computers level1 | products-level0 | | |
37 | + | DVDs level1 | products-level0 | | |
38 | + When I follow "New product or service" | |
39 | + And I select "Products level0 »" | |
40 | + Then I should see "Computers level1" | |
41 | + And I should see "DVDs level1" | |
42 | + | |
43 | + @selenium | |
44 | + Scenario: hide subcategories when select other toplevel category | |
45 | + Given the following product_categories | |
46 | + | name | | |
47 | + | Products level0 | | |
48 | + | Services level0 | | |
49 | + And the following product_categories | |
50 | + | name | parent | | |
51 | + | Computers level1 | products-level0 | | |
52 | + | Software development level1 | services-level0 | | |
53 | + When I follow "New product or service" | |
54 | + And I select "Products level0 »" | |
55 | + And I select "Computers level1" | |
56 | + And I select "Services level0 »" | |
57 | + Then I should see "Software development level1" | |
58 | + And I should not see "Computers level1" | |
59 | + | |
60 | + @selenium | |
61 | + Scenario: show hierarchy of categories | |
62 | + Given the following product_categories | |
63 | + | name | | |
64 | + | Products | | |
65 | + And the following product_category | |
66 | + | name | parent | | |
67 | + | Computers | products | | |
68 | + When I follow "New product or service" | |
69 | + And I select "Products »" | |
70 | + And I select "Computers" | |
71 | + Then I should see "Products → Computers" | |
72 | + | |
73 | + @selenium | |
74 | + Scenario: show links in hierarchy of categories and not link current category | |
75 | + Given the following product_category | |
76 | + | name | | |
77 | + | Toplevel Product Categories | | |
78 | + Given the following product_category | |
79 | + | name | parent | | |
80 | + | Category Level 1 | toplevel-product-categories | | |
81 | + When I follow "New product or service" | |
82 | + And I select "Toplevel Product Categories »" | |
83 | + And I select "Category Level 1" | |
84 | + Then I should see "Toplevel Product Categories" link | |
85 | + And I should not see "Category Level 1" link | |
86 | + | |
87 | + @selenium | |
88 | + Scenario: save button come initialy disabled | |
89 | + Given the following product_category | |
90 | + | name | | |
91 | + | Only for test | | |
92 | + When I go to /myprofile/redemoinho/manage_products/new | |
93 | + Then the "#save_and_continue" button should not be enabled | |
94 | + | |
95 | + @selenium | |
96 | + Scenario: enable save button when select one category | |
97 | + Given the following product_category | |
98 | + | name | | |
99 | + | Browsers (accept categories) | | |
100 | + When I follow "New product or service" | |
101 | + And I select "Browsers (accept categories)" | |
102 | + Then the "Save and continue" button should be enabled | |
103 | + | |
104 | + @selenium | |
105 | + Scenario: dont enable save button when select category with not accept products | |
106 | + Given the following product_category | |
107 | + | name | accept_products | | |
108 | + | Browsers | false | | |
109 | + When I follow "New product or service" | |
110 | + And I select "Browsers" | |
111 | + Then the "#save_and_continue" button should not be enabled | |
112 | + | |
113 | + @selenium | |
114 | + Scenario: save product | |
115 | + Given the following product_category | |
116 | + | name | | |
117 | + | Bicycle | | |
118 | + When I follow "New product or service" | |
119 | + And I select "Bicycle" | |
120 | + And I press "Save and continue" | |
121 | + Then I should see "Category: Bicycle" | |
122 | + | |
123 | + @selenium | |
124 | + Scenario: stay on the same place after error on save | |
125 | + Given the following product_category | |
126 | + | name | | |
127 | + | Bicycle | | |
128 | + And I follow "New product or service" | |
129 | + And I select "Bicycle" | |
130 | + And I press "Save and continue" | |
131 | + When I follow "Back" | |
132 | + And I follow "New product or service" | |
133 | + And I select "Bicycle" | |
134 | + And I press "Save and continue" | |
135 | + Then I should be on Rede Moinho's new product page | |
136 | + And I should see "Bicycle" | ... | ... |
features/search.feature
... | ... | @@ -55,10 +55,13 @@ Feature: search |
55 | 55 | Given the following enterprises |
56 | 56 | | identifier | name | |
57 | 57 | | colivre-ent | Colivre | |
58 | + And the following product_categories | |
59 | + | name | | |
60 | + | Development | | |
58 | 61 | And the following products |
59 | - | owner | name | | |
60 | - | colivre-ent | social networks consultancy | | |
61 | - | colivre-ent | wikis consultancy | | |
62 | + | owner | category | name | | |
63 | + | colivre-ent | development | social networks consultancy | | |
64 | + | colivre-ent | development | wikis consultancy | | |
62 | 65 | When I go to the search page |
63 | 66 | And I fill in "query" with "wikis" |
64 | 67 | And I press "Search" | ... | ... |
features/step_definitions/custom_webrat_steps.rb
1 | -When /^I should see "([^\"]+)" link$/ do |link| | |
2 | - response.should have_selector("a", :content => link) | |
1 | +When /^I should see "([^\"]+)" link$/ do |text| | |
2 | + response.should have_selector("a:contains('#{text}')") | |
3 | 3 | end |
4 | 4 | |
5 | -When /^I should not see "([^\"]+)" link$/ do |link| | |
6 | - response.should_not have_selector("a", :content => link) | |
5 | +When /^I should not see "([^\"]+)" link$/ do |text| | |
6 | + response.should_not have_selector("a:contains('#{text}')") | |
7 | 7 | end |
8 | 8 | |
9 | 9 | Then /^I should be exactly on (.+)$/ do |page_name| |
10 | 10 | URI.parse(current_url).request_uri.should == path_to(page_name) |
11 | 11 | end |
12 | + | |
13 | +When /^I select "([^\"]*)"$/ do |value| | |
14 | + select(value) | |
15 | + # FIXME ugly hack to make selenium tests waiting to render page | |
16 | + # "select(value, :wait_for => :ajax)" did not effect | |
17 | + if selenium | |
18 | + selenium.wait_for_ajax | |
19 | + end | |
20 | +end | ... | ... |
features/step_definitions/noosfero_steps.rb
... | ... | @@ -61,7 +61,8 @@ Given /^the following products$/ do |table| |
61 | 61 | table.hashes.each do |item| |
62 | 62 | data = item.dup |
63 | 63 | owner = Enterprise[data.delete("owner")] |
64 | - Product.create!(data.merge(:enterprise => owner)) | |
64 | + category = Category.find_by_slug(data.delete("category")) | |
65 | + Product.create!(data.merge(:enterprise => owner, :product_category => category)) | |
65 | 66 | end |
66 | 67 | end |
67 | 68 | |
... | ... | @@ -84,6 +85,18 @@ Given /^the following validation info$/ do |table| |
84 | 85 | end |
85 | 86 | end |
86 | 87 | |
88 | +Given /^the following (product_categories|product_category|category|categories)$/ do |kind,table| | |
89 | + klass = kind.singularize.camelize.constantize | |
90 | + table.hashes.each do |row| | |
91 | + parent = row.delete("parent") | |
92 | + if parent | |
93 | + parent = Category.find_by_slug(parent) | |
94 | + row.merge!({:parent_id => parent.id}) | |
95 | + end | |
96 | + category = klass.create!({:environment_id => Environment.default.id}.merge(row)) | |
97 | + end | |
98 | +end | |
99 | + | |
87 | 100 | Given /^I am logged in as "(.+)"$/ do |username| |
88 | 101 | visit('/account/logout') |
89 | 102 | visit('/account/login') | ... | ... |
features/step_definitions/selenium_steps.rb
... | ... | @@ -3,8 +3,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "pat |
3 | 3 | def string_to_element_locator(selector) |
4 | 4 | if selector.gsub!(/^\./, '') |
5 | 5 | "css=[class='#{selector}']" |
6 | + elsif selector.gsub!(/^value\./, '') | |
7 | + "xpath=//input[@value='#{selector}']" | |
8 | + elsif selector.gsub!(/^#/, '') | |
9 | + "css=[id='#{selector}']" | |
6 | 10 | else |
7 | - raise "I can't find '#{selector}'!" | |
11 | + selector | |
8 | 12 | end |
9 | 13 | end |
10 | 14 | |
... | ... | @@ -19,3 +23,11 @@ end |
19 | 23 | When /^I click "([^\"]*)"$/ do |selector| |
20 | 24 | selenium.click(string_to_element_locator(selector)) |
21 | 25 | end |
26 | + | |
27 | +Then /^the "([^\"]*)" button should not be enabled$/ do |text| | |
28 | + selenium.is_editable(string_to_element_locator(text)).should be_false | |
29 | +end | |
30 | + | |
31 | +Then /^the "([^\"]*)" button should be enabled$/ do |text| | |
32 | + selenium.is_editable(string_to_element_locator("value.#{text}")).should be_true | |
33 | +end | ... | ... |
features/support/paths.rb
... | ... | @@ -51,6 +51,9 @@ module NavigationHelpers |
51 | 51 | when /^(.+)'s members management/ |
52 | 52 | '/myprofile/%s/profile_members' % Profile.find_by_name($1).identifier |
53 | 53 | |
54 | + when /^(.+)'s new product page/ | |
55 | + '/myprofile/%s/manage_products/new' % Profile.find_by_name($1).identifier | |
56 | + | |
54 | 57 | # Add more mappings here. |
55 | 58 | # Here is a more fancy example: |
56 | 59 | # | ... | ... |
149 Bytes
149 Bytes
public/javascripts/application.js
... | ... | @@ -79,6 +79,15 @@ function disable_button(button) { |
79 | 79 | button.addClassName("disabled"); |
80 | 80 | } |
81 | 81 | |
82 | +function toggleDisabled(enable, element) { | |
83 | + if (enable) { | |
84 | + enable_button(element); | |
85 | + } | |
86 | + else { | |
87 | + disable_button(element); | |
88 | + } | |
89 | +} | |
90 | + | |
82 | 91 | /* ICON SELECTOR - LinkListBlock */ |
83 | 92 | |
84 | 93 | function showIconSelector(main_div) { | ... | ... |
public/stylesheets/application.css
... | ... | @@ -113,6 +113,15 @@ a img { |
113 | 113 | border: none; |
114 | 114 | } |
115 | 115 | |
116 | +.tooltip { | |
117 | + padding: 8px; | |
118 | + border: 1px solid #FF8000; | |
119 | + background-color: #FFFF66; | |
120 | + z-index: 100; | |
121 | + -moz-border-radius: 3px; | |
122 | + -webkit-border-radius: 3px; | |
123 | +} | |
124 | + | |
116 | 125 | /*********************************************************/ |
117 | 126 | |
118 | 127 | |
... | ... | @@ -1332,6 +1341,12 @@ input.button.with-text:hover { |
1332 | 1341 | border: none; |
1333 | 1342 | } |
1334 | 1343 | |
1344 | +body.noosfero a.button.with-text.icon-none, | |
1345 | +body.noosfero input.button.with-text.icon-none { | |
1346 | + padding-left: 2px; | |
1347 | +} | |
1348 | + | |
1349 | +a.button.disabled, | |
1335 | 1350 | input.disabled { |
1336 | 1351 | opacity: 0.5; |
1337 | 1352 | filter-opacity: 50%; |
... | ... | @@ -2989,6 +3004,70 @@ h1#agenda-title { |
2989 | 3004 | |
2990 | 3005 | /* ==> public/stylesheets/controller_manage_products.css <== */ |
2991 | 3006 | |
3007 | +#new_product_title { | |
3008 | + text-align: center; | |
3009 | +} | |
3010 | +#new_product_form { | |
3011 | + border: 1px solid #AABB88; | |
3012 | + -moz-border-radius: 5px; | |
3013 | + -webkit-border-radius: 5px; | |
3014 | + background: url(/images/ccc.gif); /* image ccc.gif from http://www.wannabegirl.org/translucent */ | |
3015 | + padding: 10px 30px 20px 30px; | |
3016 | +} | |
3017 | +#categories_container_wrapper { | |
3018 | + overflow-x: scroll; | |
3019 | + margin: 10px 0 15px 0; | |
3020 | + padding: 5px; | |
3021 | + -moz-border-radius: 3px; | |
3022 | + -webkit-border-radius: 3px; | |
3023 | + background: url(/images/fff.gif); /* image fff.gif from http://www.wannabegirl.org/translucent */ | |
3024 | + border: 1px solid #CCC; | |
3025 | + border-bottom: 0; | |
3026 | + position: relative; | |
3027 | +} | |
3028 | +.categories_container { | |
3029 | + min-height: 176px; | |
3030 | + min-width: 100px; | |
3031 | + display: inline-block; | |
3032 | + position: relative; | |
3033 | +} | |
3034 | +.categories_container .categories_container { | |
3035 | + position: absolute; | |
3036 | + top: 0; | |
3037 | + left: 100%; | |
3038 | +} | |
3039 | +.msie .categories_container .categories_container { | |
3040 | + left: auto; | |
3041 | +} | |
3042 | +.categories_container select { | |
3043 | + margin-right: 10px; | |
3044 | + height: 176px; | |
3045 | +} | |
3046 | +.controller-manage_products #categories_selection_actionbar input.button { | |
3047 | + height: 23px !important; | |
3048 | +} | |
3049 | +#save_and_continue_wrapper { | |
3050 | + position: relative; | |
3051 | +} | |
3052 | +#save_and_continue_disabled_tooltip { | |
3053 | + display: none; | |
3054 | + position: absolute; | |
3055 | + top: 30px; | |
3056 | + left: 0; | |
3057 | + min-width: 250px; | |
3058 | +} | |
3059 | +.msie #save_and_continue_disabled_tooltip { | |
3060 | + font-size: small; | |
3061 | +} | |
3062 | +#save_and_continue_wrapper #save_and_continue.disabled:hover + #save_and_continue_disabled_tooltip { | |
3063 | + display: block; | |
3064 | +} | |
3065 | +#hierarchy_navigation { | |
3066 | + min-height: 1em; | |
3067 | +} | |
3068 | +.msie #hierarchy_navigation { | |
3069 | + font-size: small; | |
3070 | +} | |
2992 | 3071 | |
2993 | 3072 | /* ==> public/stylesheets/controller_memberships.css <== */ |
2994 | 3073 | /* @import url(profile-list-block.css); ==> BROKEN REFERENCE, OH MY! */ | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | +require File.dirname(__FILE__) + '/../test/test_helper' | |
4 | +include ActionController::TestProcess | |
5 | + | |
6 | +# tourn on autoflush | |
7 | +STDOUT.sync = true | |
8 | + | |
9 | +enterprises = Enterprise.all | |
10 | + | |
11 | +print "Creating products: " | |
12 | +THINGS = %w[ Car House Bicycle Book Pen Computer Webcam ] | |
13 | +COLORS = %w[ Black Red White Blue Green Purple ] | |
14 | +for thing in THINGS | |
15 | + for color in COLORS | |
16 | + name = [color, thing].join(' ') | |
17 | + rand(10).times do |i| | |
18 | + Product.create(:name => name, :enterprise_id => enterprises.rand.id, :price => (i * 13.7), :image_builder => { | |
19 | + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
20 | + }) | |
21 | + print '.' | |
22 | + end | |
23 | + end | |
24 | +end | |
25 | +puts ' done!' | ... | ... |
test/factories.rb
... | ... | @@ -212,7 +212,7 @@ module Noosfero::Factory |
212 | 212 | end |
213 | 213 | |
214 | 214 | ############################################### |
215 | - # Article | |
215 | + # Article (and friends) | |
216 | 216 | ############################################### |
217 | 217 | |
218 | 218 | def defaults_for_article |
... | ... | @@ -220,18 +220,12 @@ module Noosfero::Factory |
220 | 220 | { :name => name, :slug => name.to_slug, :path => name.to_slug } |
221 | 221 | end |
222 | 222 | |
223 | - alias :defaults_for_text_article :defaults_for_article | |
224 | - alias :defaults_for_textile_article :defaults_for_article | |
225 | - alias :defaults_for_tiny_mce_article :defaults_for_article | |
226 | - alias :defaults_for_rss_feed :defaults_for_article | |
227 | - | |
228 | - ############################################### | |
229 | - # Folder | |
230 | - ############################################### | |
231 | - | |
232 | - def defaults_for_folder | |
233 | - defaults_for_article | |
234 | - end | |
223 | + alias :defaults_for_text_article :defaults_for_article | |
224 | + alias :defaults_for_textile_article :defaults_for_article | |
225 | + alias :defaults_for_tiny_mce_article :defaults_for_article | |
226 | + alias :defaults_for_rss_feed :defaults_for_article | |
227 | + alias :defaults_for_textile_article :defaults_for_article | |
228 | + alias :defaults_for_folder :defaults_for_article | |
235 | 229 | |
236 | 230 | ############################################### |
237 | 231 | # Event |
... | ... | @@ -300,6 +294,7 @@ module Noosfero::Factory |
300 | 294 | end |
301 | 295 | |
302 | 296 | alias :defaults_for_region :defaults_for_category |
297 | + alias :defaults_for_product_category :defaults_for_category | |
303 | 298 | |
304 | 299 | ############################################### |
305 | 300 | # Box |
... | ... | @@ -327,4 +322,12 @@ module Noosfero::Factory |
327 | 322 | alias :defaults_for_create_community :defaults_for_task |
328 | 323 | alias :defaults_for_email_activation :defaults_for_task |
329 | 324 | |
325 | + ############################################### | |
326 | + # Product | |
327 | + ############################################### | |
328 | + | |
329 | + def defaults_for_product | |
330 | + { :name => 'Product ' + factory_num_seq.to_s } | |
331 | + end | |
332 | + | |
330 | 333 | end | ... | ... |
test/fixtures/roles.yml
test/functional/catalog_controller_test.rb
... | ... | @@ -10,13 +10,13 @@ class CatalogControllerTest < Test::Unit::TestCase |
10 | 10 | @request = ActionController::TestRequest.new |
11 | 11 | @response = ActionController::TestResponse.new |
12 | 12 | |
13 | - @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent') | |
13 | + @enterprise = fast_create(Enterprise, :name => 'My enterprise', :identifier => 'testent') | |
14 | + @product_category = fast_create(ProductCategory) | |
14 | 15 | end |
15 | 16 | attr_accessor :enterprise |
16 | 17 | |
17 | 18 | def test_local_files_reference |
18 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
19 | - assert_local_files_reference :get, :index, :profile => ent.identifier | |
19 | + assert_local_files_reference :get, :index, :profile => @enterprise.identifier | |
20 | 20 | end |
21 | 21 | |
22 | 22 | def test_valid_xhtml |
... | ... | @@ -35,22 +35,20 @@ class CatalogControllerTest < Test::Unit::TestCase |
35 | 35 | end |
36 | 36 | |
37 | 37 | should 'list products of enterprise' do |
38 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
39 | - get :index, :profile => ent.identifier | |
38 | + get :index, :profile => @enterprise.identifier | |
40 | 39 | assert_kind_of Array, assigns(:products) |
41 | 40 | end |
42 | 41 | |
43 | 42 | should 'show product of enterprise' do |
44 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
45 | - prod = ent.products.create!(:name => 'Product test') | |
46 | - get :show, :id => prod.id, :profile => ent.identifier | |
43 | + prod = @enterprise.products.create!(:name => 'Product test', :product_category => @product_category) | |
44 | + get :show, :id => prod.id, :profile => @enterprise.identifier | |
47 | 45 | assert_tag :tag => 'h1', :content => /#{prod.name}/ |
48 | 46 | end |
49 | 47 | |
50 | 48 | should 'link back to index from product show' do |
51 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
52 | - prod = ent.products.create!(:name => 'Product test') | |
53 | - get :show, :id => prod.id, :profile => ent.identifier | |
49 | + enterprise = Enterprise.create!(:name => 'test_enterprise_1', :identifier => 'test_enterprise_1', :environment => Environment.default) | |
50 | + prod = enterprise.products.create!(:name => 'Product test', :product_category => @product_category) | |
51 | + get :show, :id => prod.id, :profile => enterprise.identifier | |
54 | 52 | assert_tag({ |
55 | 53 | :tag => 'div', |
56 | 54 | :attributes => { |
... | ... | @@ -59,7 +57,7 @@ class CatalogControllerTest < Test::Unit::TestCase |
59 | 57 | :descendant => { |
60 | 58 | :tag => 'a', |
61 | 59 | :attributes => { |
62 | - :href => '/catalog/test_enterprise1' | |
60 | + :href => "/catalog/#{enterprise.identifier}" | |
63 | 61 | } |
64 | 62 | } |
65 | 63 | }) |
... | ... | @@ -77,43 +75,31 @@ class CatalogControllerTest < Test::Unit::TestCase |
77 | 75 | end |
78 | 76 | |
79 | 77 | should 'not show product price when listing products if not informed' do |
80 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
81 | - prod = ent.products.create!(:name => 'Product test') | |
82 | - get :index, :profile => ent.identifier | |
78 | + prod = @enterprise.products.create!(:name => 'Product test', :product_category => @product_category) | |
79 | + get :index, :profile => @enterprise.identifier | |
83 | 80 | assert_no_tag :tag => 'li', :attributes => { :class => 'product_price' }, :content => /Price:/ |
84 | 81 | end |
85 | 82 | |
86 | 83 | should 'show product price when listing products if informed' do |
87 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
88 | - prod = ent.products.create!(:name => 'Product test', :price => 50.00) | |
89 | - get :index, :profile => ent.identifier | |
84 | + prod = @enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => @product_category) | |
85 | + get :index, :profile => @enterprise.identifier | |
90 | 86 | assert_tag :tag => 'li', :attributes => { :class => 'product_price' }, :content => /Price:/ |
91 | 87 | end |
92 | 88 | |
93 | 89 | should 'not show product price when showing product if not informed' do |
94 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
95 | - prod = ent.products.create!(:name => 'Product test') | |
96 | - get :show, :id => prod.id, :profile => ent.identifier | |
90 | + prod = @enterprise.products.create!(:name => 'Product test', :product_category => @product_category) | |
91 | + get :show, :id => prod.id, :profile => @enterprise.identifier | |
97 | 92 | |
98 | 93 | assert_no_tag :tag => 'p', :attributes => { :class => 'product_price' }, :content => /Price:/ |
99 | 94 | end |
100 | 95 | |
101 | 96 | should 'show product price when showing product if informed' do |
102 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | |
103 | - prod = ent.products.create!(:name => 'Product test', :price => 50.00) | |
104 | - get :show, :id => prod.id, :profile => ent.identifier | |
97 | + prod = @enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => @product_category) | |
98 | + get :show, :id => prod.id, :profile => @enterprise.identifier | |
105 | 99 | |
106 | 100 | assert_tag :tag => 'p', :attributes => { :class => 'product_price' }, :content => /Price:/ |
107 | 101 | end |
108 | 102 | |
109 | - should 'not crash on index when product has no product_category and enterprise not enabled' do | |
110 | - ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1', :enabled => false) | |
111 | - prod = ent.products.create!(:name => 'Product test', :price => 50.00, :product_category => nil) | |
112 | - assert_nothing_raised do | |
113 | - get :index, :profile => ent.identifier | |
114 | - end | |
115 | - end | |
116 | - | |
117 | 103 | should 'link to assets products wiht product category in the link to product category on index' do |
118 | 104 | pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment) |
119 | 105 | prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc) | ... | ... |
test/functional/manage_products_controller_test.rb
... | ... | @@ -13,6 +13,8 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
13 | 13 | @response = ActionController::TestResponse.new |
14 | 14 | @enterprise = Enterprise.create(:name => 'teste', :identifier => 'test_ent') |
15 | 15 | @user = create_user_with_permission('test_user', 'manage_products', @enterprise) |
16 | + @environment = @enterprise.environment | |
17 | + @product_category = fast_create(ProductCategory) | |
16 | 18 | login_as :test_user |
17 | 19 | end |
18 | 20 | |
... | ... | @@ -48,16 +50,15 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
48 | 50 | |
49 | 51 | should "create new product" do |
50 | 52 | assert_difference Product, :count do |
51 | - post 'new', :profile => @enterprise.identifier, :product => {:name => 'test product'} | |
52 | - assert_response :redirect | |
53 | + post 'new', :profile => @enterprise.identifier, :product => {:name => 'test product', :product_category_id => @product_category.id} | |
53 | 54 | assert assigns(:product) |
54 | - assert ! assigns(:product).new_record? | |
55 | + assert !assigns(:product).new_record? | |
55 | 56 | end |
56 | 57 | end |
57 | 58 | |
58 | 59 | should "not create invalid product" do |
59 | 60 | assert_no_difference Product, :count do |
60 | - post 'new', :profile => @enterprise.identifier, :product => {:price => 'test product'} | |
61 | + post 'new', :profile => @enterprise.identifier, :product => {:name => 'test product'} | |
61 | 62 | assert_response :success |
62 | 63 | assert assigns(:product) |
63 | 64 | assert assigns(:product).new_record? |
... | ... | @@ -65,7 +66,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
65 | 66 | end |
66 | 67 | |
67 | 68 | should "get edit form" do |
68 | - p = @enterprise.products.create(:name => 'test product') | |
69 | + p = @enterprise.products.create!(:name => 'test product', :product_category => @product_category) | |
69 | 70 | get 'edit', :profile => @enterprise.identifier, :id => p.id |
70 | 71 | assert_response :success |
71 | 72 | assert assigns(:product) |
... | ... | @@ -74,7 +75,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
74 | 75 | end |
75 | 76 | |
76 | 77 | should "edit product" do |
77 | - p = @enterprise.products.create(:name => 'test product') | |
78 | + p = @enterprise.products.create!(:name => 'test product', :product_category => @product_category) | |
78 | 79 | post 'edit', :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => p.id |
79 | 80 | assert_response :redirect |
80 | 81 | assert assigns(:product) |
... | ... | @@ -83,15 +84,15 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
83 | 84 | end |
84 | 85 | |
85 | 86 | should "not edit to invalid parameters" do |
86 | - p = @enterprise.products.create(:name => 'test product') | |
87 | - post 'edit', :profile => @enterprise.identifier, :product => {:name => ''}, :id => p.id | |
87 | + p = @enterprise.products.create!(:name => 'test product', :product_category => @product_category) | |
88 | + post 'edit', :profile => @enterprise.identifier, :product => {:product_category => nil}, :id => p.id | |
88 | 89 | assert_response :success |
89 | 90 | assert assigns(:product) |
90 | 91 | assert ! assigns(:product).valid? |
91 | 92 | end |
92 | 93 | |
93 | 94 | should "destroy product" do |
94 | - p = @enterprise.products.create(:name => 'test product') | |
95 | + p = @enterprise.products.create!(:name => 'test product', :product_category => @product_category) | |
95 | 96 | assert_difference Product, :count, -1 do |
96 | 97 | post 'destroy', :profile => @enterprise.identifier, :id => p.id |
97 | 98 | assert_response :redirect |
... | ... | @@ -102,7 +103,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
102 | 103 | end |
103 | 104 | |
104 | 105 | should "fail to destroy product" do |
105 | - p = @enterprise.products.create(:name => 'test product') | |
106 | + p = @enterprise.products.create!(:name => 'test product', :product_category => @product_category) | |
106 | 107 | Product.any_instance.stubs(:destroy).returns(false) |
107 | 108 | assert_no_difference Product, :count do |
108 | 109 | post 'destroy', :profile => @enterprise.identifier, :id => p.id |
... | ... | @@ -113,54 +114,17 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
113 | 114 | end |
114 | 115 | end |
115 | 116 | |
116 | - should 'show categories list' do | |
117 | - environment = Environment.default | |
118 | - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) | |
119 | - category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) | |
120 | - category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) | |
117 | + should 'show categories selection' do | |
118 | + category1 = fast_create(ProductCategory, :name => 'Category 1') | |
119 | + category2 = fast_create(ProductCategory, :name => 'Category 2', :parent_id => category1.id) | |
120 | + category3 = fast_create(ProductCategory, :name => 'Category 3', :parent_id => category2.id) | |
121 | 121 | get :new, :profile => @enterprise.identifier |
122 | - assert_tag :tag => 'p', :content => /Select a category:/ | |
123 | - assert_tag :tag => 'a', :content => /#{category1.name}/ | |
124 | - end | |
125 | - | |
126 | - should 'show current category' do | |
127 | - environment = Environment.default | |
128 | - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) | |
129 | - category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) | |
130 | - category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) | |
131 | - get 'update_categories', :profile => @enterprise.identifier, :category_id => category2.id | |
132 | - assert_tag :tag => 'h3', :content => /Current category:/, :sibling => { :tag => 'a', :content => /#{category3.name}/ } | |
133 | - end | |
134 | - | |
135 | - should 'show subcategories list' do | |
136 | - environment = Environment.default | |
137 | - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) | |
138 | - category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) | |
139 | - category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) | |
140 | - get 'update_categories', :profile => @enterprise.identifier, :category_id => category2.id | |
141 | - assert !assigns(:categories).empty? | |
142 | - assert_tag :tag => 'h3', :content => /Categories:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ } | |
143 | - end | |
144 | - | |
145 | - should 'update subcategories' do | |
146 | - environment = Environment.default | |
147 | - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) | |
148 | - category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) | |
149 | - get 'update_categories', :profile => @enterprise.identifier, :category_id => category1.id | |
150 | - assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ | |
151 | - end | |
152 | - | |
153 | - should 'not show subcategories list when no subcategories' do | |
154 | - environment = Environment.default | |
155 | - category1 = @enterprise.products.create!(:name => 'Category 1') | |
156 | - get 'update_categories', :profile => @enterprise.identifier, :id => category1.id | |
157 | - assert_no_tag :tag => 'h3', :content => 'Categories:' | |
122 | + assert_tag :tag => 'select', :attributes => { :id => 'category_id' }, :descendant => { :tag => 'option', :content => category1.name } | |
158 | 123 | end |
159 | 124 | |
160 | 125 | should "create new product categorized" do |
161 | - environment = Environment.default | |
162 | - category1 = ProductCategory.create!(:name => 'Category 1', :environment => environment) | |
163 | - category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1) | |
126 | + category1 = fast_create(ProductCategory, :name => 'Category 1') | |
127 | + category2 = fast_create(ProductCategory, :name => 'Category 2', :parent_id => category1) | |
164 | 128 | assert_difference Product, :count do |
165 | 129 | post 'new', :profile => @enterprise.identifier, :product => { :name => 'test product', :product_category_id => category2.id } |
166 | 130 | assert_equal category2, assigns(:product).product_category |
... | ... | @@ -168,7 +132,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
168 | 132 | end |
169 | 133 | |
170 | 134 | should 'show thumbnail image when edit product' do |
171 | - p = @enterprise.products.create!(:name => 'test product1', :image_builder => { | |
135 | + p = @enterprise.products.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { | |
172 | 136 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
173 | 137 | }) |
174 | 138 | get 'edit', :profile => @enterprise.identifier, :id => p.id |
... | ... | @@ -176,85 +140,25 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
176 | 140 | end |
177 | 141 | |
178 | 142 | should 'show change image link above thumbnail image' do |
179 | - p = @enterprise.products.create!(:name => 'test product1', :image_builder => { | |
143 | + p = @enterprise.products.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { | |
180 | 144 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
181 | 145 | }) |
182 | 146 | get 'edit', :profile => @enterprise.identifier, :id => p.id |
183 | 147 | assert_tag :tag => 'a', :attributes => { :href => '#' }, :content => 'Change image' |
184 | 148 | end |
185 | 149 | |
186 | - should 'show change image field when new product' do | |
187 | - get 'new', :profile => @enterprise.identifier | |
188 | - assert_tag :tag => 'input', :attributes => { :type => 'file', :name => 'product[image_builder][uploaded_data]' } | |
189 | - end | |
190 | - | |
191 | 150 | should 'filter html from name of product' do |
192 | - category = ProductCategory.create!(:name => 'Category 1', :environment => Environment.default) | |
151 | + category = fast_create(ProductCategory, :name => 'Category 1') | |
193 | 152 | post 'new', :profile => @enterprise.identifier, :product => { :name => "<b id='html_name'>name bold</b>", :product_category_id => category.id } |
194 | 153 | assert_sanitized assigns(:product).name |
195 | 154 | end |
196 | 155 | |
197 | 156 | should 'filter html from description of product' do |
198 | - category = ProductCategory.create!(:name => 'Category 1', :environment => Environment.default) | |
157 | + category = fast_create(ProductCategory, :name => 'Category 1') | |
199 | 158 | post 'new', :profile => @enterprise.identifier, :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>", :product_category_id => category.id } |
200 | 159 | assert_sanitized assigns(:product).description |
201 | 160 | end |
202 | - | |
203 | - should 'display new consumption form' do | |
204 | - get :new_consumption, :profile => @enterprise.identifier | |
205 | - assert_tag :tag => 'h2', :content => 'Add raw material' | |
206 | - end | |
207 | - | |
208 | - should 'create consumption product' do | |
209 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
210 | - assert_difference Consumption, :count do | |
211 | - post :new_consumption, :profile => @enterprise.identifier, :consumption => { :product_category_id => product_category.id } | |
212 | - end | |
213 | - end | |
214 | - | |
215 | - should 'display list of consumption products' do | |
216 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
217 | - @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
218 | - get :index, :profile => @enterprise.identifier | |
219 | - assert_tag :tag => 'em', :content => 'extra info' | |
220 | - end | |
221 | - | |
222 | - should 'filter html from consumption specifications' do | |
223 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
224 | - post :new_consumption, :profile => @enterprise.identifier, | |
225 | - :consumption => { :product_category_id => product_category.id, :aditional_specifications => 'extra <b>info</b>' } | |
226 | - assert_sanitized assigns(:consumption).aditional_specifications | |
227 | - end | |
228 | - | |
229 | - should 'destroy consumption product' do | |
230 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
231 | - product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
232 | - assert_difference Consumption, :count, -1 do | |
233 | - post :destroy_consumption, :profile => @enterprise.identifier, :id => product.id | |
234 | - end | |
235 | - end | |
236 | 161 | |
237 | - should 'display edit consumption form' do | |
238 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
239 | - product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
240 | - get :edit_consumption, :profile => @enterprise.identifier, :id => product | |
241 | - assert_tag :tag => 'h2', :content => 'Editing Food' | |
242 | - end | |
243 | - | |
244 | - should 'update consumption product' do | |
245 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
246 | - product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
247 | - post :edit_consumption, :profile => @enterprise.identifier, :id => product, :consumption => { :aditional_specifications => 'new extra info' } | |
248 | - assert_equal 'new extra info', @enterprise.consumptions.find(product.reload.id).aditional_specifications | |
249 | - end | |
250 | - | |
251 | - should 'not show product_category field on edit consumption form' do | |
252 | - product_category = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
253 | - product = @enterprise.consumptions.create!(:product_category_id => product_category.id, :aditional_specifications => 'extra info') | |
254 | - get :edit_consumption, :profile => @enterprise.identifier, :id => product | |
255 | - assert_no_tag :tag => 'select', :attributes => { :name => 'consumption[product_category_id]' } | |
256 | - end | |
257 | - | |
258 | 162 | should 'not let users in if environment do not let' do |
259 | 163 | env = Environment.default |
260 | 164 | env.enable('disable_products_for_enterprises') |
... | ... | @@ -267,30 +171,65 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
267 | 171 | end |
268 | 172 | |
269 | 173 | should 'show top level product categories for the user to choose' do |
270 | - pc1 = ProductCategory.create!(:name => 'test_category1', :environment => Environment.default) | |
271 | - pc2 = ProductCategory.create!(:name => 'test_category2', :environment => Environment.default) | |
174 | + pc1 = fast_create(ProductCategory, :name => 'test_category1') | |
175 | + pc2 = fast_create(ProductCategory, :name => 'test_category2') | |
272 | 176 | |
273 | 177 | get :new, :profile => @enterprise.identifier |
274 | 178 | |
275 | - assert_equivalent [pc1, pc2], assigns(:categories) | |
179 | + assert_equivalent ProductCategory.top_level_for(pc1.environment), assigns(:categories) | |
276 | 180 | end |
277 | 181 | |
278 | - should 'links to products asset for consumption link' do | |
279 | - pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment) | |
280 | - @enterprise.consumptions.create!(:product_category => pc) | |
182 | + should 'links to products asset for product category link when showing' do | |
183 | + pc = fast_create(ProductCategory, :name => 'test_category') | |
184 | + p = @enterprise.products.create!(:name => 'test product', :product_category => pc) | |
281 | 185 | |
282 | - get :index, :profile => @enterprise.identifier | |
186 | + get :show, :profile => @enterprise.identifier, :id => p.id | |
283 | 187 | |
284 | 188 | assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} |
285 | 189 | end |
286 | 190 | |
287 | - should 'links to products asset for product category link when showing' do | |
288 | - pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment) | |
289 | - p = @enterprise.products.create!(:name => 'test product', :product_category => pc) | |
191 | + should 'increase level while navigate on hierarchy categories' do | |
192 | + category_level0 = fast_create(ProductCategory, :name => 'Products', :environment_id => @environment.id) | |
193 | + category_level1 = fast_create(ProductCategory, :parent_id => category_level0.id, :name => 'Shoes', :environment_id => @environment.id) | |
194 | + category_level2 = fast_create(ProductCategory, :parent_id => category_level1.id, :name => 'Athletic Shoes', :environment_id => @environment.id) | |
290 | 195 | |
291 | - get :show, :profile => @enterprise.identifier, :id => p.id | |
196 | + get :categories_for_selection, :profile => @enterprise.identifier, :category_id => category_level0.id | |
197 | + assert_equal 0, assigns(:level) | |
292 | 198 | |
293 | - assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} | |
199 | + get :categories_for_selection, :profile => @enterprise.identifier, :category_id => category_level1.id | |
200 | + assert_equal 1, assigns(:level) | |
201 | + | |
202 | + get :categories_for_selection, :profile => @enterprise.identifier, :category_id => category_level2.id | |
203 | + assert_equal 2, assigns(:level) | |
294 | 204 | end |
295 | - | |
205 | + | |
206 | + should 'remember the selected category' do | |
207 | + category0 = fast_create(ProductCategory, :name => 'Products', :environment_id => @environment.id) | |
208 | + category1 = fast_create(ProductCategory, :name => 'Shoes', :environment_id => @environment.id) | |
209 | + | |
210 | + get :categories_for_selection, :profile => @enterprise.identifier, :category_id => category0.id | |
211 | + assert_equal category0, assigns(:category) | |
212 | + | |
213 | + get :categories_for_selection, :profile => @enterprise.identifier, :category_id => category1.id | |
214 | + assert_equal category1, assigns(:category) | |
215 | + end | |
216 | + | |
217 | + should 'list top level categories when has no category_id' do | |
218 | + get :categories_for_selection, :profile => @enterprise.identifier | |
219 | + | |
220 | + assert_equal ProductCategory.top_level_for(@environment), assigns(:categories) | |
221 | + end | |
222 | + | |
223 | + should 'render dialog_error_messages template for invalid product' do | |
224 | + post :new, :profile => @enterprise.identifier, :product => { :name => 'Invalid product' } | |
225 | + assert_template 'shared/_dialog_error_messages' | |
226 | + end | |
227 | + | |
228 | + should 'render redirect_via_javascript template after save' do | |
229 | + assert_difference Product, :count do | |
230 | + post :new, :profile => @enterprise.identifier, :product => { :name => 'Invalid product', :product_category_id => @product_category.id } | |
231 | + assert_template 'shared/_redirect_via_javascript' | |
232 | + end | |
233 | + end | |
234 | + | |
296 | 235 | end | ... | ... |
test/functional/profile_design_controller_test.rb
... | ... | @@ -72,6 +72,8 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
72 | 72 | |
73 | 73 | @controller.stubs(:boxes_holder).returns(holder) |
74 | 74 | login_as 'designtestuser' |
75 | + | |
76 | + @product_category = fast_create(ProductCategory) | |
75 | 77 | end |
76 | 78 | attr_reader :profile |
77 | 79 | |
... | ... | @@ -217,8 +219,8 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
217 | 219 | block = ProductsBlock.new |
218 | 220 | |
219 | 221 | enterprise = Enterprise.create!(:name => "test", :identifier => 'testenterprise') |
220 | - p1 = enterprise.products.create!(:name => 'product one') | |
221 | - p2 = enterprise.products.create!(:name => 'product two') | |
222 | + p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
223 | + p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
222 | 224 | enterprise.boxes.first.blocks << block |
223 | 225 | enterprise.add_admin(holder) |
224 | 226 | |
... | ... | @@ -237,8 +239,8 @@ class ProfileDesignControllerTest < Test::Unit::TestCase |
237 | 239 | block = ProductsBlock.new |
238 | 240 | |
239 | 241 | enterprise = Enterprise.create!(:name => "test", :identifier => 'testenterprise') |
240 | - p1 = enterprise.products.create!(:name => 'product one') | |
241 | - p2 = enterprise.products.create!(:name => 'product two') | |
242 | + p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
243 | + p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
242 | 244 | enterprise.boxes.first.blocks << block |
243 | 245 | enterprise.add_admin(holder) |
244 | 246 | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -15,6 +15,8 @@ class SearchControllerTest < Test::Unit::TestCase |
15 | 15 | domain = Environment.default.domains.first |
16 | 16 | domain.google_maps_key = 'ENVIRONMENT_KEY' |
17 | 17 | domain.save! |
18 | + | |
19 | + @product_category = fast_create(ProductCategory) | |
18 | 20 | end |
19 | 21 | |
20 | 22 | def create_article_with_optional_category(name, profile, category = nil) |
... | ... | @@ -244,7 +246,7 @@ class SearchControllerTest < Test::Unit::TestCase |
244 | 246 | |
245 | 247 | should 'find products' do |
246 | 248 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
247 | - prod = ent.products.create!(:name => 'a beautiful product') | |
249 | + prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
248 | 250 | get 'index', :query => 'beautiful', :find_in => ['products'] |
249 | 251 | assert_includes assigns(:results)[:products], prod |
250 | 252 | end |
... | ... | @@ -252,8 +254,8 @@ class SearchControllerTest < Test::Unit::TestCase |
252 | 254 | should 'find products in a specific category' do |
253 | 255 | ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category) |
254 | 256 | ent2 = create_profile_with_optional_category(Enterprise, 'teste2') |
255 | - prod1 = ent1.products.create!(:name => 'a beautiful product') | |
256 | - prod2 = ent2.products.create!(:name => 'another beautiful product') | |
257 | + prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
258 | + prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | |
257 | 259 | get :index, :category_path => @category.path.split('/'), :query => 'beautiful', :find_in => ['products'] |
258 | 260 | assert_includes assigns(:results)[:products], prod1 |
259 | 261 | assert_not_includes assigns(:results)[:products], prod2 |
... | ... | @@ -265,8 +267,8 @@ class SearchControllerTest < Test::Unit::TestCase |
265 | 267 | |
266 | 268 | ent1 = create_profile_with_optional_category(Enterprise, 'teste1') |
267 | 269 | ent2 = create_profile_with_optional_category(Enterprise, 'teste2') |
268 | - prod1 = ent1.products.create!(:name => 'a beautiful product') | |
269 | - prod2 = ent2.products.create!(:name => 'another beautiful product') | |
270 | + prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
271 | + prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | |
270 | 272 | |
271 | 273 | get :assets, :asset => 'products' |
272 | 274 | assert_equivalent [prod2, prod1], assigns(:results)[:products] |
... | ... | @@ -278,11 +280,11 @@ class SearchControllerTest < Test::Unit::TestCase |
278 | 280 | |
279 | 281 | # in category |
280 | 282 | ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category) |
281 | - prod1 = ent1.products.create!(:name => 'a beautiful product') | |
283 | + prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
282 | 284 | |
283 | 285 | # not in category |
284 | 286 | ent2 = create_profile_with_optional_category(Enterprise, 'teste2') |
285 | - prod2 = ent2.products.create!(:name => 'another beautiful product') | |
287 | + prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | |
286 | 288 | |
287 | 289 | get :assets, :asset => 'products', :category_path => [ 'my-category' ] |
288 | 290 | |
... | ... | @@ -301,7 +303,7 @@ class SearchControllerTest < Test::Unit::TestCase |
301 | 303 | |
302 | 304 | should 'display search results' do |
303 | 305 | ent = create_profile_with_optional_category(Enterprise, 'display enterprise') |
304 | - product = ent.products.create!(:name => 'display product') | |
306 | + product = ent.products.create!(:name => 'display product', :product_category => @product_category) | |
305 | 307 | person = create_user('displayperson').person; person.name = 'display person'; person.save! |
306 | 308 | article = person.articles.create!(:name => 'display article') |
307 | 309 | event = Event.new(:name => 'display event', :start_date => Date.today); event.profile = person; event.save! |
... | ... | @@ -919,9 +921,9 @@ class SearchControllerTest < Test::Unit::TestCase |
919 | 921 | should 'search for products by origin and radius correctly' do |
920 | 922 | s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) |
921 | 923 | e1 = create_profile_with_optional_category(Enterprise, 'test ent 1', nil, :lat => -12.97, :lng => -38.51) |
922 | - p1 = e1.products.create!(:name => 'test_product1') | |
924 | + p1 = e1.products.create!(:name => 'test_product1', :product_category => @product_category) | |
923 | 925 | e2 = create_profile_with_optional_category(Enterprise, 'test ent 2', nil, :lat => -14.97, :lng => -40.51) |
924 | - p2 = e2.products.create!(:name => 'test_product2') | |
926 | + p2 = e2.products.create!(:name => 'test_product2', :product_category => @product_category) | |
925 | 927 | |
926 | 928 | get :assets, :asset => 'products', :city => s.id, :radius => 15 |
927 | 929 | |
... | ... | @@ -988,7 +990,7 @@ class SearchControllerTest < Test::Unit::TestCase |
988 | 990 | should 'find products when enterprises has own hostname' do |
989 | 991 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
990 | 992 | ent.domains << Domain.new(:name => 'testent.com'); ent.save! |
991 | - prod = ent.products.create!(:name => 'a beautiful product') | |
993 | + prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
992 | 994 | get 'index', :query => 'beautiful', :find_in => ['products'] |
993 | 995 | assert_includes assigns(:results)[:products], prod |
994 | 996 | end | ... | ... |
test/test_helper.rb
... | ... | @@ -177,6 +177,40 @@ class Test::Unit::TestCase |
177 | 177 | |
178 | 178 | end |
179 | 179 | |
180 | +module NoosferoTestHelper | |
181 | + def link_to(content, url, options = {}) | |
182 | + "<a href='#{url.to_s}'>#{content}</a>" | |
183 | + end | |
184 | + | |
185 | + def content_tag(tag, content, options = {}) | |
186 | + "<#{tag}>#{content}</#{tag}>" | |
187 | + end | |
188 | + | |
189 | + def submit_tag(content, options = {}) | |
190 | + content | |
191 | + end | |
192 | + | |
193 | + def remote_function(options = {}) | |
194 | + '' | |
195 | + end | |
196 | + | |
197 | + def tag(tag) | |
198 | + "<#{tag}/>" | |
199 | + end | |
200 | + | |
201 | + def options_from_collection_for_select(collection, value_method, content_method) | |
202 | + "<option value='fake value'>fake content</option>" | |
203 | + end | |
204 | + | |
205 | + def select_tag(id, collection, options = {}) | |
206 | + "<select id='#{id}'>fake content</select>" | |
207 | + end | |
208 | + | |
209 | + def options_for_select(collection) | |
210 | + collection.map{|item| "<option value='#{item[1]}'>#{item[0]}</option>"}.join("\n") | |
211 | + end | |
212 | +end | |
213 | + | |
180 | 214 | class ActionController::IntegrationTest |
181 | 215 | def assert_can_login |
182 | 216 | assert_tag :tag => 'a', :attributes => { :id => 'link_login' } | ... | ... |
test/unit/article_test.rb
... | ... | @@ -796,7 +796,7 @@ class ArticleTest < Test::Unit::TestCase |
796 | 796 | end |
797 | 797 | |
798 | 798 | should 'update slug from name' do |
799 | - article = create(Article, :name => 'A test article', :profile_id => profile.id) | |
799 | + article = Article.create!(:name => 'A test article', :profile_id => profile.id) | |
800 | 800 | assert_equal 'a-test-article', article.slug |
801 | 801 | article.name = 'Changed name' |
802 | 802 | assert_equal 'changed-name', article.slug | ... | ... |
test/unit/category_finder_test.rb
... | ... | @@ -5,6 +5,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
5 | 5 | def setup |
6 | 6 | @category = Category.create!(:name => 'my category', :environment => Environment.default) |
7 | 7 | @finder = CategoryFinder.new(@category) |
8 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
8 | 9 | |
9 | 10 | Profile.rebuild_index |
10 | 11 | end |
... | ... | @@ -48,7 +49,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
48 | 49 | ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :category_ids => [@category.id]) |
49 | 50 | |
50 | 51 | # not in category |
51 | - ent2 = Enterprise.create!(:name => 'beautiful enterprise 2', :identifier => 'test2') | |
52 | + ent2 = fast_create(Enterprise, :name => 'beautiful enterprise 2', :identifier => 'test2') | |
52 | 53 | |
53 | 54 | list = @finder.find(:enterprises, 'beautiful') |
54 | 55 | assert_includes list, ent1 |
... | ... | @@ -65,8 +66,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
65 | 66 | end |
66 | 67 | |
67 | 68 | should 'search for communities in a specific category' do |
68 | - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) | |
69 | - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) | |
69 | + c1 = fast_create(Community, :name => 'a beautiful community', :identifier => 'bea_comm', :environment_id => Environment.default.id) | |
70 | + c2 = fast_create(Community, :name => 'another beautiful community', :identifier => 'an_bea_comm', :environment_id => Environment.default.id) | |
70 | 71 | c1.add_category(@category); c1.save! |
71 | 72 | |
72 | 73 | list = @finder.find(:communities, 'beautiful') |
... | ... | @@ -75,10 +76,10 @@ class CategoryFinderTest < ActiveSupport::TestCase |
75 | 76 | end |
76 | 77 | |
77 | 78 | should 'search for products in a specific category' do |
78 | - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category(@category) | |
79 | - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') | |
80 | - prod1 = ent1.products.create!(:name => 'a beautiful product') | |
81 | - prod2 = ent2.products.create!(:name => 'another beautiful product') | |
79 | + ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1'); ent1.add_category(@category) | |
80 | + ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2') | |
81 | + prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
82 | + prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | |
82 | 83 | |
83 | 84 | list = @finder.find(:products, 'beautiful') |
84 | 85 | assert_includes list, prod1 |
... | ... | @@ -86,8 +87,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
86 | 87 | end |
87 | 88 | |
88 | 89 | should 'search people in category hierarchy' do |
89 | - parent = Category.create!(:name => 'parent category', :environment => Environment.default) | |
90 | - child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent) | |
90 | + parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id) | |
91 | + child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id) | |
91 | 92 | p1 = create_user('people_1').person |
92 | 93 | p1.name = 'a beautiful person' |
93 | 94 | p1.add_category(child) |
... | ... | @@ -100,8 +101,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
100 | 101 | end |
101 | 102 | |
102 | 103 | should 'search article in category hierarchy' do |
103 | - parent = Category.create!(:name => 'parent category', :environment => Environment.default) | |
104 | - child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent) | |
104 | + parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id) | |
105 | + child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id) | |
105 | 106 | |
106 | 107 | p1 = create_user('people_1').person |
107 | 108 | |
... | ... | @@ -174,8 +175,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
174 | 175 | end |
175 | 176 | |
176 | 177 | should 'not return the same result twice' do |
177 | - parent = Category.create!(:name => 'parent category', :environment => Environment.default) | |
178 | - child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent) | |
178 | + parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id) | |
179 | + child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id) | |
179 | 180 | p1 = create_user('people_1').person |
180 | 181 | p1.name = 'a beautiful person' |
181 | 182 | p1.category_ids = [child.id, parent.id]; p1.save! |
... | ... | @@ -205,7 +206,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
205 | 206 | should 'find person and enterprise by radius and region' do |
206 | 207 | finder = CategoryFinder.new(@category) |
207 | 208 | |
208 | - region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
209 | + region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) | |
209 | 210 | ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [@category.id]) |
210 | 211 | p1 = create_user('test2').person |
211 | 212 | p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(@category); p1.save! |
... | ... | @@ -229,7 +230,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
229 | 230 | e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id]) |
230 | 231 | |
231 | 232 | # not in category |
232 | - e2 = Event.create!(:name => 'e2', :profile => person, :start_date => Date.new(2008,1,15)) | |
233 | + e2 = fast_create(Event, :name => 'e2', :profile_id => person.id, :start_date => Date.new(2008,1,15)) | |
233 | 234 | |
234 | 235 | events = finder.current_events(2008, 1) |
235 | 236 | assert_includes events, e1 |
... | ... | @@ -246,16 +247,16 @@ class CategoryFinderTest < ActiveSupport::TestCase |
246 | 247 | # event 2 is created after, but must be listed before (since it happens before) |
247 | 248 | upcoming_event_2 = Event.create!(:name => 'upcoming event 2', :profile => person, :start_date => Date.new(2008,1,25), :category_ids => [@category.id]) |
248 | 249 | upcoming_event_1 = Event.create!(:name => 'upcoming event 1', :profile => person, :start_date => Date.new(2008,1,20), :category_ids => [@category.id]) |
249 | - not_in_category = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,20)) | |
250 | + not_in_category = fast_create(Event, :name => 'e1', :profile_id => person.id, :start_date => Date.new(2008,1,20)) | |
250 | 251 | |
251 | 252 | assert_equal [upcoming_event_1, upcoming_event_2], @finder.upcoming_events |
252 | 253 | end |
253 | 254 | |
254 | 255 | should 'find person and enterprise in category by radius and region even without query' do |
255 | - cat = Category.create!(:name => 'test category', :environment => Environment.default) | |
256 | + cat = fast_create(Category, :name => 'test category', :environment_id => Environment.default.id) | |
256 | 257 | finder = CategoryFinder.new(cat) |
257 | 258 | |
258 | - region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
259 | + region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) | |
259 | 260 | ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [cat.id]) |
260 | 261 | p1 = create_user('test2').person |
261 | 262 | p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(cat); p1.save! |
... | ... | @@ -273,13 +274,13 @@ class CategoryFinderTest < ActiveSupport::TestCase |
273 | 274 | end |
274 | 275 | |
275 | 276 | should 'find products in category wihin product category' do |
276 | - cat = Category.create!(:name => 'test category', :environment => Environment.default) | |
277 | + cat = fast_create(Category, :name => 'test category', :environment_id => Environment.default.id) | |
277 | 278 | finder = CategoryFinder.new(cat) |
278 | 279 | |
279 | - prod_cat = ProductCategory.create!(:name => 'test product category', :environment => Environment.default) | |
280 | + prod_cat = fast_create(ProductCategory, :name => 'test product category', :environment_id => Environment.default.id) | |
280 | 281 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :category_ids => [cat.id]) |
281 | 282 | prod1 = ent.products.create!(:name => 'test product 1', :product_category => prod_cat) |
282 | - prod2 = ent.products.create!(:name => 'test product 2') | |
283 | + prod2 = ent.products.create!(:name => 'test product 2', :product_category => @product_category) | |
283 | 284 | |
284 | 285 | prods = finder.find(:products, nil, :product_category => prod_cat) |
285 | 286 | |
... | ... | @@ -288,8 +289,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
288 | 289 | end |
289 | 290 | |
290 | 291 | should 'find enterprises by its products categories without query' do |
291 | - pc1 = ProductCategory.create!(:name => 'test_cat1', :environment => Environment.default) | |
292 | - pc2 = ProductCategory.create!(:name => 'test_cat2', :environment => Environment.default) | |
292 | + pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) | |
293 | + pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) | |
293 | 294 | |
294 | 295 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) |
295 | 296 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
... | ... | @@ -303,8 +304,8 @@ class CategoryFinderTest < ActiveSupport::TestCase |
303 | 304 | end |
304 | 305 | |
305 | 306 | should 'find enterprises by its products categories with query' do |
306 | - pc1 = ProductCategory.create!(:name => 'test_cat1', :environment => Environment.default) | |
307 | - pc2 = ProductCategory.create!(:name => 'test_cat2', :environment => Environment.default) | |
307 | + pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) | |
308 | + pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) | |
308 | 309 | |
309 | 310 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) |
310 | 311 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
... | ... | @@ -318,10 +319,10 @@ class CategoryFinderTest < ActiveSupport::TestCase |
318 | 319 | end |
319 | 320 | |
320 | 321 | should 'count product categories results by products' do |
321 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
322 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
323 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
324 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
322 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
323 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) | |
324 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
325 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
325 | 326 | |
326 | 327 | ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) |
327 | 328 | p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) |
... | ... | @@ -330,7 +331,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
330 | 331 | p4 = ent.products.create!(:name => 'test product 4', :product_category => pc2) # not in the count |
331 | 332 | p5 = ent.products.create!(:name => 'test product 5', :product_category => pc3) # not in the count |
332 | 333 | |
333 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
334 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
334 | 335 | p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) |
335 | 336 | |
336 | 337 | counts = @finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id], [p1.id, p2.id, p3.id, p5.id, p6.id] ) |
... | ... | @@ -342,10 +343,10 @@ class CategoryFinderTest < ActiveSupport::TestCase |
342 | 343 | end |
343 | 344 | |
344 | 345 | should 'count product categories results by all products' do |
345 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
346 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
347 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
348 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
346 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
347 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) | |
348 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
349 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
349 | 350 | |
350 | 351 | ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) |
351 | 352 | p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) |
... | ... | @@ -353,7 +354,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
353 | 354 | p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) |
354 | 355 | p4 = ent.products.create!(:name => 'test product 4', :product_category => pc3) # not in the count |
355 | 356 | |
356 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
357 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
357 | 358 | p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) |
358 | 359 | |
359 | 360 | |
... | ... | @@ -366,10 +367,10 @@ class CategoryFinderTest < ActiveSupport::TestCase |
366 | 367 | end |
367 | 368 | |
368 | 369 | should 'count product categories results by enterprises' do |
369 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
370 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
371 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
372 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
370 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
371 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) | |
372 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
373 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
373 | 374 | |
374 | 375 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) |
375 | 376 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
... | ... | @@ -384,7 +385,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
384 | 385 | ent5.products.create!(:name => 'test product 5', :product_category => pc2) |
385 | 386 | ent5.products.create!(:name => 'test product 6', :product_category => pc3) |
386 | 387 | |
387 | - ent6 = Enterprise.create!(:name => 'test enterprise 6', :identifier => 'test_ent6') | |
388 | + ent6 = fast_create(Enterprise, :name => 'test enterprise 6', :identifier => 'test_ent6') | |
388 | 389 | p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) |
389 | 390 | |
390 | 391 | counts = @finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id], [ent1.id, ent2.id, ent3.id, ent4.id] ) |
... | ... | @@ -396,10 +397,10 @@ class CategoryFinderTest < ActiveSupport::TestCase |
396 | 397 | end |
397 | 398 | |
398 | 399 | should 'count product categories results by all enterprises' do |
399 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
400 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
401 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
402 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
400 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
401 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default, :parent_id => pc1.id) | |
402 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
403 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
403 | 404 | |
404 | 405 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) |
405 | 406 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
... | ... | @@ -412,7 +413,7 @@ class CategoryFinderTest < ActiveSupport::TestCase |
412 | 413 | ent4.products.create!(:name => 'test product 4', :product_category => pc2) |
413 | 414 | ent4.products.create!(:name => 'test product 5', :product_category => pc3) |
414 | 415 | |
415 | - ent5 = Enterprise.create!(:name => 'test enterprise 5', :identifier => 'test_ent5') | |
416 | + ent5 = fast_create(Enterprise, :name => 'test enterprise 5', :identifier => 'test_ent5') | |
416 | 417 | p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) |
417 | 418 | |
418 | 419 | counts = @finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id] ) |
... | ... | @@ -438,12 +439,12 @@ class CategoryFinderTest < ActiveSupport::TestCase |
438 | 439 | person = create_user('teste').person |
439 | 440 | |
440 | 441 | # in category |
441 | - art1 = TextileArticle.create!(:name => 'an article to be found', :profile => person) | |
442 | + art1 = fast_create(TextileArticle, :name => 'an article to be found', :profile_id => person.id) | |
442 | 443 | art1.add_category(@category) |
443 | 444 | art1.save! |
444 | 445 | |
445 | 446 | # not in category |
446 | - art2 = TextileArticle.create!(:name => 'another article to be found', :profile => person) | |
447 | + art2 = fast_create(TextileArticle, :name => 'another article to be found', :profile_id => person.id) | |
447 | 448 | |
448 | 449 | list = @finder.find(:text_articles, 'found') |
449 | 450 | assert_includes list, art1 | ... | ... |
test/unit/category_test.rb
... | ... | @@ -137,7 +137,7 @@ class CategoryTest < Test::Unit::TestCase |
137 | 137 | end |
138 | 138 | |
139 | 139 | def test_should_refuse_to_duplicate_slug_under_the_same_parent |
140 | - c1 = create(Category, :name => 'test category', :environment_id => @env.id) | |
140 | + c1 = Category.create!(:name => 'test category', :environment_id => @env.id) | |
141 | 141 | c2 = Category.new(:name => 'Test: Category', :environment_id => @env.id) |
142 | 142 | |
143 | 143 | assert !c2.valid? |
... | ... | @@ -157,9 +157,9 @@ class CategoryTest < Test::Unit::TestCase |
157 | 157 | end |
158 | 158 | |
159 | 159 | def test_renaming_a_category_should_change_path_of_children |
160 | - c1 = create(Category, :name => 'parent', :environment_id => @env.id) | |
161 | - c2 = create(Category, :name => 'child', :environment_id => @env.id, :parent_id => c1.id) | |
162 | - c3 = create(Category, :name => 'grandchild', :environment_id => @env.id, :parent_id => c2.id) | |
160 | + c1 = Category.create!(:name => 'parent', :environment_id => @env.id) | |
161 | + c2 = Category.create!(:name => 'child', :environment_id => @env.id, :parent_id => c1.id) | |
162 | + c3 = Category.create!(:name => 'grandchild', :environment_id => @env.id, :parent_id => c2.id) | |
163 | 163 | |
164 | 164 | c1.name = 'parent new name' |
165 | 165 | c1.save! |
... | ... | @@ -311,13 +311,14 @@ class CategoryTest < Test::Unit::TestCase |
311 | 311 | end |
312 | 312 | |
313 | 313 | should 'have products through enteprises' do |
314 | + product_category = fast_create(ProductCategory, :name => 'Products', :environment_id => Environment.default.id) | |
314 | 315 | c = @env.categories.build(:name => 'my category'); c.save! |
315 | 316 | ent1 = fast_create(Enterprise, :identifier => 'enterprise_1', :name => 'Enterprise one') |
316 | 317 | ent1.add_category c |
317 | 318 | ent2 = fast_create(Enterprise, :identifier => 'enterprise_2', :name => 'Enterprise one') |
318 | 319 | ent2.add_category c |
319 | - prod1 = ent1.products.create!(:name => 'test_prod1') | |
320 | - prod2 = ent2.products.create!(:name => 'test_prod2') | |
320 | + prod1 = ent1.products.create!(:name => 'test_prod1', :product_category => product_category) | |
321 | + prod2 = ent2.products.create!(:name => 'test_prod2', :product_category => product_category) | |
321 | 322 | assert_includes c.products, prod1 |
322 | 323 | assert_includes c.products, prod2 |
323 | 324 | end |
... | ... | @@ -384,4 +385,8 @@ class CategoryTest < Test::Unit::TestCase |
384 | 385 | assert_equal 2, c.children.size |
385 | 386 | end |
386 | 387 | |
388 | + should 'accept_products is true by default' do | |
389 | + assert Category.new.accept_products? | |
390 | + end | |
391 | + | |
387 | 392 | end | ... | ... |
test/unit/enterprise_homepage_test.rb
... | ... | @@ -4,6 +4,7 @@ class EnterpriseHomepageTest < Test::Unit::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @profile = create_user('testing').person |
7 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
7 | 8 | end |
8 | 9 | attr_reader :profile |
9 | 10 | |
... | ... | @@ -25,8 +26,8 @@ class EnterpriseHomepageTest < Test::Unit::TestCase |
25 | 26 | end |
26 | 27 | |
27 | 28 | should 'display products list' do |
28 | - ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise') | |
29 | - prod = ent.products.create!(:name => 'Product test') | |
29 | + ent = fast_create(Enterprise, :identifier => 'test_enterprise', :name => 'Test enteprise') | |
30 | + prod = ent.products.create!(:name => 'Product test', :product_category => @product_category) | |
30 | 31 | a = EnterpriseHomepage.new(:name => 'article homepage') |
31 | 32 | ent.articles << a |
32 | 33 | result = a.to_html |
... | ... | @@ -37,8 +38,8 @@ class EnterpriseHomepageTest < Test::Unit::TestCase |
37 | 38 | e = Environment.default |
38 | 39 | e.enable('disable_products_for_enterprises') |
39 | 40 | e.save! |
40 | - ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise', :environment => e) | |
41 | - prod = ent.products.create!(:name => 'Product test') | |
41 | + ent = fast_create(Enterprise, :identifier => 'test_enterprise', :name => 'Test enteprise', :environment_id => e.id) | |
42 | + prod = ent.products.create!(:name => 'Product test', :product_category => @product_category) | |
42 | 43 | a = EnterpriseHomepage.new(:name => 'article homepage') |
43 | 44 | ent.articles << a |
44 | 45 | result = a.to_html |
... | ... | @@ -46,8 +47,8 @@ class EnterpriseHomepageTest < Test::Unit::TestCase |
46 | 47 | end |
47 | 48 | |
48 | 49 | should 'display link to product' do |
49 | - ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise') | |
50 | - prod = ent.products.create!(:name => 'Product test') | |
50 | + ent = fast_create(Enterprise, :identifier => 'test_enterprise', :name => 'Test enteprise') | |
51 | + prod = ent.products.create!(:name => 'Product test', :product_category => @product_category) | |
51 | 52 | a = EnterpriseHomepage.new(:name => 'article homepage') |
52 | 53 | ent.articles << a |
53 | 54 | result = a.to_html | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class EnterpriseTest < Test::Unit::TestCase |
4 | 4 | fixtures :profiles, :environments, :users |
5 | 5 | |
6 | + def setup | |
7 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
8 | + end | |
9 | + | |
6 | 10 | def test_identifier_validation |
7 | 11 | p = Enterprise.new |
8 | 12 | p.valid? |
... | ... | @@ -46,9 +50,9 @@ class EnterpriseTest < Test::Unit::TestCase |
46 | 50 | end |
47 | 51 | |
48 | 52 | should 'remove products when removing enterprise' do |
49 | - e = fast_create(Enterprise) | |
50 | - e.products.build(:name => 'One product').save! | |
51 | - e.products.build(:name => 'Another product').save! | |
53 | + e = fast_create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise') | |
54 | + e.products.create!(:name => 'One product', :product_category => @product_category) | |
55 | + e.products.create!(:name => 'Another product', :product_category => @product_category) | |
52 | 56 | |
53 | 57 | assert_difference Product, :count, -2 do |
54 | 58 | e.destroy |
... | ... | @@ -63,7 +67,7 @@ class EnterpriseTest < Test::Unit::TestCase |
63 | 67 | end |
64 | 68 | |
65 | 69 | should 'create default set of blocks' do |
66 | - e = Enterprise.create!(:name => 'my new community', :identifier => 'mynewcommunity') | |
70 | + e = Enterprise.create(:name => 'my new community', :identifier => 'mynewcommunity') | |
67 | 71 | |
68 | 72 | assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation' |
69 | 73 | |
... | ... | @@ -77,11 +81,11 @@ class EnterpriseTest < Test::Unit::TestCase |
77 | 81 | end |
78 | 82 | |
79 | 83 | should 'be found in search for its product categories' do |
80 | - ent1 = fast_create(Enterprise) | |
81 | - prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) | |
84 | + ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1') | |
85 | + prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id) | |
82 | 86 | prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) |
83 | 87 | |
84 | - ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2') | |
88 | + ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') | |
85 | 89 | |
86 | 90 | result = Enterprise.find_by_contents(prod_cat.name) |
87 | 91 | |
... | ... | @@ -90,12 +94,12 @@ class EnterpriseTest < Test::Unit::TestCase |
90 | 94 | end |
91 | 95 | |
92 | 96 | should 'be found in search for its product categories hierarchy' do |
93 | - ent1 = fast_create(Enterprise) | |
94 | - prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) | |
95 | - prod_child = ProductCategory.create!(:name => 'pchild', :environment => Environment.default, :parent => prod_cat) | |
97 | + ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1') | |
98 | + prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id) | |
99 | + prod_child = fast_create(ProductCategory, :name => 'pchild', :environment_id => Environment.default.id, :parent_id => prod_cat.id) | |
96 | 100 | prod = ent1.products.create!(:name => 'teste', :product_category => prod_child) |
97 | 101 | |
98 | - ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2') | |
102 | + ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') | |
99 | 103 | |
100 | 104 | result = Enterprise.find_by_contents(prod_cat.name) |
101 | 105 | |
... | ... | @@ -104,7 +108,7 @@ class EnterpriseTest < Test::Unit::TestCase |
104 | 108 | end |
105 | 109 | |
106 | 110 | should 'not allow to add new members' do |
107 | - o = fast_create(Enterprise) | |
111 | + o = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') | |
108 | 112 | p = create_user('mytestuser').person |
109 | 113 | |
110 | 114 | o.add_member(p) |
... | ... | @@ -114,7 +118,7 @@ class EnterpriseTest < Test::Unit::TestCase |
114 | 118 | end |
115 | 119 | |
116 | 120 | should 'allow to remove members' do |
117 | - c = fast_create(Enterprise) | |
121 | + c = fast_create(Enterprise, :name => 'my other test profile', :identifier => 'myothertestprofile') | |
118 | 122 | c.expects(:closed?).returns(false) |
119 | 123 | p = create_user('myothertestuser').person |
120 | 124 | |
... | ... | @@ -126,7 +130,7 @@ class EnterpriseTest < Test::Unit::TestCase |
126 | 130 | end |
127 | 131 | |
128 | 132 | should 'have foudation_year' do |
129 | - ent = fast_create(Enterprise) | |
133 | + ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent') | |
130 | 134 | |
131 | 135 | assert_respond_to ent, 'foundation_year' |
132 | 136 | assert_respond_to ent, 'foundation_year=' |
... | ... | @@ -140,13 +144,13 @@ class EnterpriseTest < Test::Unit::TestCase |
140 | 144 | end |
141 | 145 | |
142 | 146 | should 'block' do |
143 | - ent = fast_create(Enterprise) | |
147 | + ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent') | |
144 | 148 | ent.block |
145 | 149 | assert Enterprise.find(ent.id).blocked? |
146 | 150 | end |
147 | 151 | |
148 | 152 | should 'unblock' do |
149 | - ent = fast_create(Enterprise) | |
153 | + ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent') | |
150 | 154 | ent.data[:blocked] = true |
151 | 155 | ent.save |
152 | 156 | ent.unblock |
... | ... | @@ -154,7 +158,7 @@ class EnterpriseTest < Test::Unit::TestCase |
154 | 158 | end |
155 | 159 | |
156 | 160 | should 'enable and make user admin' do |
157 | - ent = fast_create(Enterprise, :enabled => false) | |
161 | + ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) | |
158 | 162 | p = create_user('test_user').person |
159 | 163 | |
160 | 164 | assert ent.enable(p) |
... | ... | @@ -164,7 +168,7 @@ class EnterpriseTest < Test::Unit::TestCase |
164 | 168 | end |
165 | 169 | |
166 | 170 | should 'replace template if environment allows' do |
167 | - template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false) | |
171 | + template = fast_create(Enterprise, :name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false) | |
168 | 172 | template.boxes.destroy_all |
169 | 173 | template.boxes << Box.new |
170 | 174 | template.boxes[0].blocks << Block.new |
... | ... | @@ -175,7 +179,7 @@ class EnterpriseTest < Test::Unit::TestCase |
175 | 179 | e.enterprise_template = template |
176 | 180 | e.save! |
177 | 181 | |
178 | - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) | |
182 | + ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) | |
179 | 183 | |
180 | 184 | p = create_user('test_user').person |
181 | 185 | ent.enable(p) |
... | ... | @@ -185,7 +189,7 @@ class EnterpriseTest < Test::Unit::TestCase |
185 | 189 | end |
186 | 190 | |
187 | 191 | should 'not replace template if environment doesnt allow' do |
188 | - inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') | |
192 | + inactive_template = fast_create(Enterprise, :name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') | |
189 | 193 | inactive_template.boxes.destroy_all |
190 | 194 | inactive_template.boxes << Box.new |
191 | 195 | inactive_template.save! |
... | ... | @@ -220,14 +224,14 @@ class EnterpriseTest < Test::Unit::TestCase |
220 | 224 | |
221 | 225 | should 'not create activation task when enabled = true' do |
222 | 226 | assert_no_difference EnterpriseActivation, :count do |
223 | - Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => true) | |
227 | + fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => true) | |
224 | 228 | end |
225 | 229 | end |
226 | 230 | |
227 | 231 | should 'be able to enable even if there are mandatory fields blank' do |
228 | 232 | # enterprise is created, waiting for being enabled |
229 | - environment = Environment.create!(:name => 'my test environment') | |
230 | - enterprise = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :enabled => false, :environment => environment) | |
233 | + environment = fast_create(Environment, :name => 'my test environment') | |
234 | + enterprise = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent', :enabled => false, :environment_id => environment.id) | |
231 | 235 | |
232 | 236 | # administrator decides now that the 'city' field is mandatory |
233 | 237 | environment.custom_enterprise_fields = { 'city' => { 'active' => 'true', 'required' => 'true' } } |
... | ... | @@ -241,22 +245,11 @@ class EnterpriseTest < Test::Unit::TestCase |
241 | 245 | end |
242 | 246 | |
243 | 247 | should 'list product categories full name' do |
244 | - full_name = mock | |
245 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
246 | - p = ent.products.create!(:name => 'test prod') | |
247 | - p.expects(:category_full_name).returns(full_name) | |
248 | + subcategory = fast_create(ProductCategory, :name => 'Products subcategory', :parent_id => @product_category.id) | |
249 | + ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent') | |
250 | + p = ent.products.create!(:name => 'test prod', :product_category => subcategory) | |
248 | 251 | |
249 | - assert_equal [full_name], ent.product_categories | |
250 | - end | |
251 | - | |
252 | - should 'not return nil values when have uncategorized products' do | |
253 | - full_name = mock | |
254 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
255 | - p1 = ent.products.create!(:name => 'test prod 1') | |
256 | - p1.expects(:category_full_name).returns(full_name) | |
257 | - p2 = ent.products.create!(:name => 'test prod 2') | |
258 | - | |
259 | - assert_equal [full_name], ent.product_categories | |
252 | + assert_equal [p.category_full_name], ent.product_categories | |
260 | 253 | end |
261 | 254 | |
262 | 255 | should 'default home page is a EnterpriseHomepage' do |
... | ... | @@ -268,18 +261,18 @@ class EnterpriseTest < Test::Unit::TestCase |
268 | 261 | env = Environment.default |
269 | 262 | env.enable('disable_products_for_enterprises') |
270 | 263 | env.save! |
271 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
264 | + ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent') | |
272 | 265 | assert_not_includes ent.blocks.map(&:class), ProductsBlock |
273 | 266 | end |
274 | 267 | |
275 | 268 | should 'have a enterprise template' do |
276 | 269 | env = Environment.create!(:name => 'test env') |
277 | - p = Enterprise.create!(:name => 'test_com', :identifier => 'test_com', :environment => env) | |
270 | + p = fast_create(Enterprise, :name => 'test_com', :identifier => 'test_com', :environment_id => env.id) | |
278 | 271 | assert_kind_of Enterprise, p.template |
279 | 272 | end |
280 | 273 | |
281 | 274 | should 'contact us enabled by default' do |
282 | - e = Enterprise.create!(:name => 'test_com', :identifier => 'test_com', :environment => Environment.default) | |
275 | + e = fast_create(Enterprise, :name => 'test_com', :identifier => 'test_com', :environment_id => Environment.default.id) | |
283 | 276 | assert e.enable_contact_us |
284 | 277 | end |
285 | 278 | |
... | ... | @@ -349,7 +342,7 @@ class EnterpriseTest < Test::Unit::TestCase |
349 | 342 | end |
350 | 343 | |
351 | 344 | should 'have inactive_template when creating enterprise and feature is enabled' do |
352 | - inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') | |
345 | + inactive_template = fast_create(Enterprise, :name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') | |
353 | 346 | inactive_template.boxes.destroy_all |
354 | 347 | inactive_template.boxes << Box.new |
355 | 348 | inactive_template.save! |
... | ... | @@ -364,7 +357,7 @@ class EnterpriseTest < Test::Unit::TestCase |
364 | 357 | end |
365 | 358 | |
366 | 359 | should 'have active_template when creating enterprise and feature is disabled' do |
367 | - inactive_template = Enterprise.create!(:name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') | |
360 | + inactive_template = fast_create(Enterprise, :name => 'inactive enteprise template', :identifier => 'inactive_enterprise_template') | |
368 | 361 | inactive_template.boxes.destroy_all |
369 | 362 | inactive_template.boxes << Box.new |
370 | 363 | inactive_template.save! |
... | ... | @@ -381,15 +374,16 @@ class EnterpriseTest < Test::Unit::TestCase |
381 | 374 | should 'collect the highlighted products with image' do |
382 | 375 | env = Environment.default |
383 | 376 | e1 = fast_create(Enterprise) |
384 | - p1 = e1.products.create!(:name => 'test_prod1') | |
377 | + p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => @product_category.id) | |
385 | 378 | products = [] |
386 | 379 | 3.times {|n| |
387 | - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, :highlighted => true, :image_builder => { | |
388 | - :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
389 | - })) | |
380 | + products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, | |
381 | + :highlighted => true, :product_category_id => @product_category.id, | |
382 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | |
383 | + )) | |
390 | 384 | } |
391 | - Product.create!(:name => "product 4", :enterprise_id => e1.id, :highlighted => true) | |
392 | - Product.create!(:name => "product 5", :enterprise_id => e1.id, :image_builder => { | |
385 | + Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => @product_category.id, :highlighted => true) | |
386 | + Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => @product_category.id, :image_builder => { | |
393 | 387 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
394 | 388 | }) |
395 | 389 | assert_equal products, e1.highlighted_products_with_image | ... | ... |
test/unit/environment_finder_test.rb
... | ... | @@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class EnvironmentFinderTest < ActiveSupport::TestCase |
4 | 4 | |
5 | + def setup | |
6 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
7 | + end | |
8 | + | |
5 | 9 | should 'find articles' do |
6 | 10 | person = create_user('teste').person |
7 | 11 | art = person.articles.build(:name => 'an article to be found'); art.save! |
... | ... | @@ -23,8 +27,8 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
23 | 27 | |
24 | 28 | should 'find products' do |
25 | 29 | finder = EnvironmentFinder.new(Environment.default) |
26 | - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') | |
27 | - prod = ent.products.create!(:name => 'a beautiful product') | |
30 | + ent = fast_create(Enterprise, :name => 'teste', :identifier => 'teste') | |
31 | + prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
28 | 32 | assert_includes finder.find(:products, 'beautiful'), prod |
29 | 33 | end |
30 | 34 | |
... | ... | @@ -36,14 +40,14 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
36 | 40 | |
37 | 41 | should 'list recent enterprises' do |
38 | 42 | finder = EnvironmentFinder.new(Environment.default) |
39 | - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') | |
43 | + ent = fast_create(Enterprise, :name => 'teste', :identifier => 'teste') | |
40 | 44 | assert_includes finder.recent('enterprises'), ent |
41 | 45 | end |
42 | 46 | |
43 | 47 | should 'not list more enterprises than limit' do |
44 | 48 | finder = EnvironmentFinder.new(Environment.default) |
45 | - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1') | |
46 | - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') | |
49 | + ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1') | |
50 | + ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2') | |
47 | 51 | recent = finder.recent('enterprises', 1) |
48 | 52 | |
49 | 53 | assert_equal 1, recent.size |
... | ... | @@ -51,8 +55,8 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
51 | 55 | |
52 | 56 | should 'paginate the list of more enterprises than limit' do |
53 | 57 | finder = EnvironmentFinder.new(Environment.default) |
54 | - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1') | |
55 | - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') | |
58 | + ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1') | |
59 | + ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2') | |
56 | 60 | |
57 | 61 | assert_equal 1, finder.find('enterprises', nil, :per_page => 1, :page => 1).size |
58 | 62 | end |
... | ... | @@ -72,11 +76,11 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
72 | 76 | should 'find person and enterprise by radius and region' do |
73 | 77 | finder = EnvironmentFinder.new(Environment.default) |
74 | 78 | |
75 | - region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
76 | - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
79 | + region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) | |
80 | + ent1 = fast_create(Enterprise, :name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
77 | 81 | p1 = create_user('test2').person |
78 | 82 | p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save! |
79 | - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0) | |
83 | + ent2 = fast_create(Enterprise, :name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0) | |
80 | 84 | p2 = create_user('test4').person |
81 | 85 | p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save! |
82 | 86 | |
... | ... | @@ -92,11 +96,11 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
92 | 96 | should 'find person and enterprise by radius and region even without query' do |
93 | 97 | finder = EnvironmentFinder.new(Environment.default) |
94 | 98 | |
95 | - region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
96 | - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
99 | + region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) | |
100 | + ent1 = fast_create(Enterprise, :name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
97 | 101 | p1 = create_user('test2').person |
98 | 102 | p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save! |
99 | - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0) | |
103 | + ent2 = fast_create(Enterprise, :name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0) | |
100 | 104 | p2 = create_user('test4').person |
101 | 105 | p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save! |
102 | 106 | |
... | ... | @@ -111,10 +115,10 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
111 | 115 | |
112 | 116 | should 'find products wihin product category' do |
113 | 117 | finder = EnvironmentFinder.new(Environment.default) |
114 | - cat = ProductCategory.create!(:name => 'test category', :environment => Environment.default) | |
115 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent') | |
118 | + cat = fast_create(ProductCategory, :name => 'test category', :environment_id => Environment.default.id) | |
119 | + ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent') | |
116 | 120 | prod1 = ent.products.create!(:name => 'test product 1', :product_category => cat) |
117 | - prod2 = ent.products.create!(:name => 'test product 2') | |
121 | + prod2 = ent.products.create!(:name => 'test product 2', :product_category => @product_category) | |
118 | 122 | |
119 | 123 | prods = finder.find(:products, nil, :product_category => cat) |
120 | 124 | |
... | ... | @@ -124,12 +128,12 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
124 | 128 | |
125 | 129 | should 'find products wihin product category with query' do |
126 | 130 | finder = EnvironmentFinder.new(Environment.default) |
127 | - cat = ProductCategory.create!(:name => 'test category', :environment => Environment.default) | |
128 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent') | |
131 | + cat = fast_create(ProductCategory, :name => 'test category', :environment_id => Environment.default.id) | |
132 | + ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent') | |
129 | 133 | prod1 = ent.products.create!(:name => 'test product a_word 1', :product_category => cat) |
130 | 134 | prod2 = ent.products.create!(:name => 'test product b_word 1', :product_category => cat) |
131 | - prod3 = ent.products.create!(:name => 'test product a_word 2') | |
132 | - prod4 = ent.products.create!(:name => 'test product b_word 2') | |
135 | + prod3 = ent.products.create!(:name => 'test product a_word 2', :product_category => @product_category) | |
136 | + prod4 = ent.products.create!(:name => 'test product b_word 2', :product_category => @product_category) | |
133 | 137 | |
134 | 138 | prods = finder.find(:products, 'a_word', :product_category => cat) |
135 | 139 | |
... | ... | @@ -142,9 +146,9 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
142 | 146 | should 'find enterprises in alphabetical order of name' do |
143 | 147 | finder = EnvironmentFinder.new(Environment.default) |
144 | 148 | |
145 | - ent1 = Enterprise.create!(:name => 'test enterprise B', :identifier => 'test_ent_b') | |
146 | - ent2 = Enterprise.create!(:name => 'test enterprise A', :identifier => 'test_ent_a') | |
147 | - ent3 = Enterprise.create!(:name => 'test enterprise C', :identifier => 'test_ent_c') | |
149 | + ent1 = fast_create(Enterprise, :name => 'test enterprise B', :identifier => 'test_ent_b') | |
150 | + ent2 = fast_create(Enterprise, :name => 'test enterprise A', :identifier => 'test_ent_a') | |
151 | + ent3 = fast_create(Enterprise, :name => 'test enterprise C', :identifier => 'test_ent_c') | |
148 | 152 | |
149 | 153 | ents = finder.find(:enterprises, nil) |
150 | 154 | |
... | ... | @@ -155,12 +159,12 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
155 | 159 | should 'find enterprises by its products categories' do |
156 | 160 | finder = EnvironmentFinder.new(Environment.default) |
157 | 161 | |
158 | - pc1 = ProductCategory.create!(:name => 'test_cat1', :environment => Environment.default) | |
159 | - pc2 = ProductCategory.create!(:name => 'test_cat2', :environment => Environment.default) | |
162 | + pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) | |
163 | + pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) | |
160 | 164 | |
161 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
165 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
162 | 166 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
163 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
167 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
164 | 168 | ent2.products.create!(:name => 'test product 2', :product_category => pc2) |
165 | 169 | |
166 | 170 | ents = finder.find(:enterprises, nil, :product_category => pc1) |
... | ... | @@ -172,12 +176,12 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
172 | 176 | should 'find enterprises by its products categories with query' do |
173 | 177 | finder = EnvironmentFinder.new(Environment.default) |
174 | 178 | |
175 | - pc1 = ProductCategory.create!(:name => 'test_cat1', :environment => Environment.default) | |
176 | - pc2 = ProductCategory.create!(:name => 'test_cat2', :environment => Environment.default) | |
179 | + pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) | |
180 | + pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) | |
177 | 181 | |
178 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
182 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
179 | 183 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
180 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
184 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
181 | 185 | ent2.products.create!(:name => 'test product 2', :product_category => pc2) |
182 | 186 | |
183 | 187 | ents = finder.find(:enterprises, 'test', :product_category => pc1) |
... | ... | @@ -189,12 +193,12 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
189 | 193 | should 'find enterprises by a product category with name with spaces' do |
190 | 194 | finder = EnvironmentFinder.new(Environment.default) |
191 | 195 | |
192 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
193 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
196 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
197 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
194 | 198 | |
195 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
199 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
196 | 200 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
197 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
201 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
198 | 202 | ent2.products.create!(:name => 'test product 2', :product_category => pc2) |
199 | 203 | |
200 | 204 | ents = finder.find(:enterprises, 'test', :product_category => pc1) |
... | ... | @@ -206,13 +210,13 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
206 | 210 | should 'count product categories results by products' do |
207 | 211 | finder = EnvironmentFinder.new(Environment.default) |
208 | 212 | |
209 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
210 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
211 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
212 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
213 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
214 | + pc11= fast_create(ProductCategory, :name => 'test cat11',:environment_id => Environment.default.id, :parent_id => pc1.id) | |
215 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
216 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
213 | 217 | |
214 | 218 | |
215 | - ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
219 | + ent = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
216 | 220 | p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) |
217 | 221 | p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11) |
218 | 222 | p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) |
... | ... | @@ -230,13 +234,13 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
230 | 234 | should 'count product categories results by all products' do |
231 | 235 | finder = EnvironmentFinder.new(Environment.default) |
232 | 236 | |
233 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
234 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
235 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
236 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
237 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
238 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) | |
239 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
240 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
237 | 241 | |
238 | 242 | |
239 | - ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
243 | + ent = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
240 | 244 | p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) |
241 | 245 | p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11) |
242 | 246 | p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) |
... | ... | @@ -253,21 +257,21 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
253 | 257 | should 'count product categories results by enterprises' do |
254 | 258 | finder = EnvironmentFinder.new(Environment.default) |
255 | 259 | |
256 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
257 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
258 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
259 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
260 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
261 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) | |
262 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
263 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
260 | 264 | |
261 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
265 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
262 | 266 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
263 | 267 | ent1.products.create!(:name => 'test product 2', :product_category => pc1) |
264 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
268 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
265 | 269 | ent2.products.create!(:name => 'test product 2', :product_category => pc11) |
266 | - ent3 = Enterprise.create!(:name => 'test enterprise 3', :identifier => 'test_ent3') | |
270 | + ent3 = fast_create(Enterprise, :name => 'test enterprise 3', :identifier => 'test_ent3') | |
267 | 271 | ent3.products.create!(:name => 'test product 3', :product_category => pc2) |
268 | - ent4 = Enterprise.create!(:name => 'test enterprise 4', :identifier => 'test_ent4') | |
272 | + ent4 = fast_create(Enterprise, :name => 'test enterprise 4', :identifier => 'test_ent4') | |
269 | 273 | ent4.products.create!(:name => 'test product 4', :product_category => pc2) |
270 | - ent5 = Enterprise.create!(:name => 'test enterprise 5', :identifier => 'test_ent5') # not in the count | |
274 | + ent5 = fast_create(Enterprise, :name => 'test enterprise 5', :identifier => 'test_ent5') # not in the count | |
271 | 275 | ent5.products.create!(:name => 'test product 5', :product_category => pc2) |
272 | 276 | ent5.products.create!(:name => 'test product 6', :product_category => pc3) |
273 | 277 | |
... | ... | @@ -282,19 +286,19 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
282 | 286 | should 'count product categories results by all enterprises' do |
283 | 287 | finder = EnvironmentFinder.new(Environment.default) |
284 | 288 | |
285 | - pc1 = ProductCategory.create!(:name => 'test cat1', :environment => Environment.default) | |
286 | - pc11 = ProductCategory.create!(:name => 'test cat11', :environment => Environment.default, :parent => pc1) | |
287 | - pc2 = ProductCategory.create!(:name => 'test cat2', :environment => Environment.default) | |
288 | - pc3 = ProductCategory.create!(:name => 'test cat3', :environment => Environment.default) | |
289 | + pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) | |
290 | + pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) | |
291 | + pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) | |
292 | + pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) | |
289 | 293 | |
290 | - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1') | |
294 | + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') | |
291 | 295 | ent1.products.create!(:name => 'test product 1', :product_category => pc1) |
292 | 296 | ent1.products.create!(:name => 'test product 2', :product_category => pc1) |
293 | - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2') | |
297 | + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') | |
294 | 298 | ent2.products.create!(:name => 'test product 2', :product_category => pc11) |
295 | - ent3 = Enterprise.create!(:name => 'test enterprise 3', :identifier => 'test_ent3') | |
299 | + ent3 = fast_create(Enterprise, :name => 'test enterprise 3', :identifier => 'test_ent3') | |
296 | 300 | ent3.products.create!(:name => 'test product 3', :product_category => pc2) |
297 | - ent4 = Enterprise.create!(:name => 'test enterprise 4', :identifier => 'test_ent4') | |
301 | + ent4 = fast_create(Enterprise, :name => 'test enterprise 4', :identifier => 'test_ent4') | |
298 | 302 | ent4.products.create!(:name => 'test product 4', :product_category => pc2) |
299 | 303 | ent4.products.create!(:name => 'test product 5', :product_category => pc3) |
300 | 304 | |
... | ... | @@ -323,8 +327,8 @@ class EnvironmentFinderTest < ActiveSupport::TestCase |
323 | 327 | |
324 | 328 | date_range = Date.new(2009, 11, 28)..Date.new(2009, 12, 3) |
325 | 329 | |
326 | - event_in_range = Event.create!(:name => 'Event in range', :profile => person, :start_date => Date.new(2009, 11, 27), :end_date => date_range.last) | |
327 | - event_out_of_range = Event.create!(:name => 'Event out of range', :profile => person, :start_date => Date.new(2009, 12, 4)) | |
330 | + event_in_range = fast_create(Event, :name => 'Event in range', :profile_id => person.id, :start_date => Date.new(2009, 11, 27), :end_date => date_range.last) | |
331 | + event_out_of_range = fast_create(Event, :name => 'Event out of range', :profile_id => person.id, :start_date => Date.new(2009, 12, 4)) | |
328 | 332 | |
329 | 333 | events_found = finder.find(:events, '', :date_range => date_range) |
330 | 334 | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -367,9 +367,10 @@ class EnvironmentTest < Test::Unit::TestCase |
367 | 367 | end |
368 | 368 | |
369 | 369 | should 'have products through enterprises' do |
370 | + product_category = fast_create(ProductCategory, :name => 'Products', :environment_id => Environment.default.id) | |
370 | 371 | env = Environment.default |
371 | 372 | e1 = fast_create(Enterprise) |
372 | - p1 = e1.products.create!(:name => 'test_prod1') | |
373 | + p1 = e1.products.create!(:name => 'test_prod1', :product_category => product_category) | |
373 | 374 | |
374 | 375 | assert_includes env.products, p1 |
375 | 376 | end |
... | ... | @@ -377,15 +378,17 @@ class EnvironmentTest < Test::Unit::TestCase |
377 | 378 | should 'collect the highlighted products with image through enterprises' do |
378 | 379 | env = Environment.default |
379 | 380 | e1 = fast_create(Enterprise) |
380 | - p1 = e1.products.create!(:name => 'test_prod1') | |
381 | + category = fast_create(ProductCategory) | |
382 | + p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) | |
381 | 383 | products = [] |
382 | 384 | 3.times {|n| |
383 | - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, :highlighted => true, :image_builder => { | |
384 | - :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
385 | - })) | |
385 | + products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, | |
386 | + :product_category_id => category.id, :highlighted => true, | |
387 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | |
388 | + )) | |
386 | 389 | } |
387 | - Product.create!(:name => "product 4", :enterprise_id => e1.id, :highlighted => true) | |
388 | - Product.create!(:name => "product 5", :enterprise_id => e1.id, :image_builder => { | |
390 | + Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => category.id, :highlighted => true) | |
391 | + Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => category.id, :image_builder => { | |
389 | 392 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
390 | 393 | }) |
391 | 394 | assert_equal products, env.highlighted_products_with_image | ... | ... |
test/unit/featured_products_block_test.rb
... | ... | @@ -11,7 +11,8 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
11 | 11 | |
12 | 12 | should 'refer to products' do |
13 | 13 | products = [] |
14 | - 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id)) } | |
14 | + category = fast_create(ProductCategory) | |
15 | + 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } | |
15 | 16 | featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id)) |
16 | 17 | assert_equal products, featured_products_block.products |
17 | 18 | end |
... | ... | @@ -62,10 +63,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
62 | 63 | block = FeaturedProductsBlock.new() |
63 | 64 | block.product_ids = [] |
64 | 65 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
66 | + category = fast_create(ProductCategory) | |
65 | 67 | 3.times {|n| |
66 | - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :image_builder => { | |
67 | - :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
68 | - }) | |
68 | + Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, | |
69 | + :highlighted => true, :product_category_id => category.id, | |
70 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | |
71 | + ) | |
69 | 72 | } |
70 | 73 | @environment.boxes.first.blocks<< block |
71 | 74 | |
... | ... | @@ -76,8 +79,9 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
76 | 79 | block = FeaturedProductsBlock.new() |
77 | 80 | block.product_ids = [] |
78 | 81 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
82 | + category = fast_create(ProductCategory) | |
79 | 83 | 3.times {|n| |
80 | - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true) | |
84 | + Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) | |
81 | 85 | } |
82 | 86 | @environment.boxes.first.blocks<< block |
83 | 87 | |
... | ... | @@ -88,8 +92,9 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
88 | 92 | block = FeaturedProductsBlock.new() |
89 | 93 | block.product_ids = [] |
90 | 94 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
95 | + category = fast_create(ProductCategory) | |
91 | 96 | 3.times {|n| |
92 | - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :image_builder => { | |
97 | + Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { | |
93 | 98 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
94 | 99 | }) |
95 | 100 | } |
... | ... | @@ -109,14 +114,16 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
109 | 114 | block = FeaturedProductsBlock.new() |
110 | 115 | block.product_ids = [] |
111 | 116 | enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
117 | + category = fast_create(ProductCategory) | |
112 | 118 | products = [] |
113 | 119 | 3.times {|n| |
114 | - products.push(Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :image_builder => { | |
115 | - :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | |
116 | - })) | |
120 | + products.push(Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, | |
121 | + :highlighted => true, :product_category_id => category.id, | |
122 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | |
123 | + )) | |
117 | 124 | } |
118 | - Product.create!(:name => "product 4", :enterprise_id => enterprise.id, :highlighted => true) | |
119 | - Product.create!(:name => "product 5", :enterprise_id => enterprise.id, :image_builder => { | |
125 | + Product.create!(:name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true) | |
126 | + Product.create!(:name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { | |
120 | 127 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
121 | 128 | }) |
122 | 129 | @environment.boxes.first.blocks<< block | ... | ... |
... | ... | @@ -0,0 +1,44 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ManageProductsHelperTest < Test::Unit::TestCase | |
4 | + | |
5 | + include ManageProductsHelper | |
6 | + include ContentViewerHelper | |
7 | + include ActionView::Helpers::AssetTagHelper | |
8 | + include ApplicationHelper | |
9 | + | |
10 | + def setup | |
11 | + stubs(:show_date).returns('') | |
12 | + @environment = Environment.default | |
13 | + @profile = create_user('blog_helper_test').person | |
14 | + end | |
15 | + | |
16 | + should 'omit second category when lenght of all names is over 60 chars' do | |
17 | + category_1 = fast_create(ProductCategory, :name => ('Category 1' * 5), :environment_id => @environment.id) | |
18 | + category_2 = fast_create(ProductCategory, :name => ('Category 2' * 5), :environment_id => @environment.id, :parent_id => category_1.id) | |
19 | + category_3 = fast_create(ProductCategory, :name => ('Category 3' * 5), :environment_id => @environment.id, :parent_id => category_2.id) | |
20 | + | |
21 | + assert_match /Category 1/, hierarchy_category_navigation(category_3) | |
22 | + assert_no_match /Category 2/, hierarchy_category_navigation(category_3) | |
23 | + end | |
24 | + | |
25 | + should 'show dots when lenght of all names is over 60 chars' do | |
26 | + category_1 = fast_create(ProductCategory, :name => ('Category 1' * 5), :environment_id => @environment.id) | |
27 | + category_2 = fast_create(ProductCategory, :name => ('Category 2' * 5), :environment_id => @environment.id, :parent_id => category_1.id) | |
28 | + category_3 = fast_create(ProductCategory, :name => ('Category 3' * 5), :environment_id => @environment.id, :parent_id => category_2.id) | |
29 | + | |
30 | + assert_match /…/, hierarchy_category_navigation(category_3) | |
31 | + end | |
32 | + | |
33 | + should 'display select for categories' do | |
34 | + category_1 = fast_create(ProductCategory, :name => 'Category 1', :environment_id => @environment.id) | |
35 | + fast_create(ProductCategory, :name => 'Category 2.1', :environment_id => @environment.id, :parent_id => category_1.id) | |
36 | + fast_create(ProductCategory, :name => 'Category 2.2', :environment_id => @environment.id, :parent_id => category_1.id) | |
37 | + | |
38 | + assert_tag_in_string select_for_categories(category_1.children(true), 1), :tag => 'select', :attributes => {:id => 'category_id'} | |
39 | + end | |
40 | + | |
41 | + protected | |
42 | + include NoosferoTestHelper | |
43 | + | |
44 | +end | ... | ... |
test/unit/product_test.rb
... | ... | @@ -2,53 +2,49 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ProductTest < Test::Unit::TestCase |
4 | 4 | |
5 | + def setup | |
6 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
7 | + end | |
8 | + | |
5 | 9 | should 'create product' do |
6 | 10 | assert_difference Product, :count do |
7 | - p = Product.new(:name => 'test product1') | |
11 | + p = Product.new(:name => 'test product1', :product_category => @product_category) | |
8 | 12 | assert p.save |
9 | 13 | end |
10 | 14 | end |
11 | 15 | |
12 | 16 | should 'destroy product' do |
13 | - p = Product.create(:name => 'test product2') | |
17 | + p = fast_create(Product, :name => 'test product2', :product_category_id => @product_category.id) | |
14 | 18 | assert_difference Product, :count, -1 do |
15 | 19 | p.destroy |
16 | 20 | end |
17 | 21 | end |
18 | 22 | |
19 | - should 'name be unique' do | |
20 | - Product.create(:name => 'test product3') | |
21 | - assert_no_difference Product, :count do | |
22 | - p = Product.new(:name => 'test product3') | |
23 | - assert !p.save | |
24 | - end | |
25 | - end | |
26 | - | |
27 | 23 | should 'list recent products' do |
28 | - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'my-enterprise') | |
24 | + enterprise = fast_create(Enterprise, :name => "My enterprise", :identifier => 'my-enterprise') | |
29 | 25 | Product.delete_all |
30 | 26 | |
31 | - p1 = enterprise.products.create!(:name => 'product 1') | |
32 | - p2 = enterprise.products.create!(:name => 'product 2') | |
33 | - p3 = enterprise.products.create!(:name => 'product 3') | |
27 | + p1 = enterprise.products.create!(:name => 'product 1', :product_category => @product_category) | |
28 | + p2 = enterprise.products.create!(:name => 'product 2', :product_category => @product_category) | |
29 | + p3 = enterprise.products.create!(:name => 'product 3', :product_category => @product_category) | |
34 | 30 | |
35 | 31 | assert_equal [p3, p2, p1], Product.recent |
36 | 32 | end |
37 | 33 | |
38 | 34 | should 'list recent products with limit' do |
39 | - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'my-enterprise') | |
35 | + enterprise = fast_create(Enterprise, :name => "My enterprise", :identifier => 'my-enterprise') | |
40 | 36 | Product.delete_all |
41 | 37 | |
42 | - p1 = enterprise.products.create!(:name => 'product 1') | |
43 | - p2 = enterprise.products.create!(:name => 'product 2') | |
44 | - p3 = enterprise.products.create!(:name => 'product 3') | |
38 | + p1 = enterprise.products.create!(:name => 'product 1', :product_category => @product_category) | |
39 | + p2 = enterprise.products.create!(:name => 'product 2', :product_category => @product_category) | |
40 | + p3 = enterprise.products.create!(:name => 'product 3', :product_category => @product_category) | |
45 | 41 | |
46 | 42 | assert_equal [p3, p2], Product.recent(2) |
47 | 43 | end |
48 | 44 | |
49 | 45 | should 'save image on create product' do |
50 | 46 | assert_difference Product, :count do |
51 | - p = Product.create!(:name => 'test product1', :image_builder => { | |
47 | + p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { | |
52 | 48 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
53 | 49 | }) |
54 | 50 | assert_equal p.image(true).filename, 'rails.png' |
... | ... | @@ -71,7 +67,7 @@ class ProductTest < Test::Unit::TestCase |
71 | 67 | end |
72 | 68 | |
73 | 69 | should 'be indexed by category full name' do |
74 | - p = Product.new(:name => 'a test product') | |
70 | + p = Product.new(:name => 'a test product', :product_category => @product_category) | |
75 | 71 | p.expects(:category_full_name).returns('interesting category') |
76 | 72 | p.save! |
77 | 73 | |
... | ... | @@ -79,8 +75,8 @@ class ProductTest < Test::Unit::TestCase |
79 | 75 | end |
80 | 76 | |
81 | 77 | should 'have same lat and lng of its enterprise' do |
82 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_enterprise', :lat => 30.0, :lng => 30.0 ) | |
83 | - prod = ent.products.create!(:name => 'test product') | |
78 | + ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_enterprise', :lat => 30.0, :lng => 30.0) | |
79 | + prod = ent.products.create!(:name => 'test product', :product_category => @product_category) | |
84 | 80 | |
85 | 81 | prod = Product.find(prod.id) |
86 | 82 | assert_equal ent.lat, prod.lat |
... | ... | @@ -88,8 +84,8 @@ class ProductTest < Test::Unit::TestCase |
88 | 84 | end |
89 | 85 | |
90 | 86 | should 'update lat and lng of product afer update enterprise' do |
91 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_enterprise', :lat => 30.0, :lng => 30.0 ) | |
92 | - prod = ent.products.create!(:name => 'test product') | |
87 | + ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_enterprise', :lat => 30.0, :lng => 30.0) | |
88 | + prod = ent.products.create!(:name => 'test product', :product_category => @product_category) | |
93 | 89 | |
94 | 90 | ent.lat = 45.0; ent.lng = 45.0; ent.save! |
95 | 91 | |
... | ... | @@ -100,8 +96,8 @@ class ProductTest < Test::Unit::TestCase |
100 | 96 | end |
101 | 97 | |
102 | 98 | should 'be searched by radius and distance' do |
103 | - prod1 = Product.create!(:name => 'prod test 1', :lat => 30.0, :lng => 30.0) | |
104 | - prod2 = Product.create!(:name => 'prod test 2', :lat => 45.0, :lng => 45.0) | |
99 | + prod1 = fast_create(Product, :name => 'prod test 1', :lat => 30.0, :lng => 30.0, :product_category_id => @product_category.id) | |
100 | + prod2 = fast_create(Product, :name => 'prod test 2', :lat => 45.0, :lng => 45.0, :product_category_id => @product_category.id) | |
105 | 101 | |
106 | 102 | prods = Product.find(:all, :within => 10, :origin => [30.0, 30.0]) |
107 | 103 | |
... | ... | @@ -121,9 +117,9 @@ class ProductTest < Test::Unit::TestCase |
121 | 117 | end |
122 | 118 | |
123 | 119 | should 'categorize also with product categorization' do |
124 | - cat = ProductCategory.create(:name => 'test cat', :environment => Environment.default) | |
125 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
126 | - p = ent.products.create!(:name => 'test product') | |
120 | + cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id) | |
121 | + ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent') | |
122 | + p = ent.products.new(:name => 'test product') | |
127 | 123 | p.product_category = cat |
128 | 124 | p.save! |
129 | 125 | |
... | ... | @@ -131,10 +127,10 @@ class ProductTest < Test::Unit::TestCase |
131 | 127 | end |
132 | 128 | |
133 | 129 | should 'categorize parent cateogries with product categorization' do |
134 | - parent_cat = ProductCategory.create(:name => 'test cat', :environment => Environment.default) | |
135 | - child_cat = ProductCategory.create(:name => 'test cat', :environment => Environment.default, :parent => parent_cat) | |
136 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
137 | - p = ent.products.create!(:name => 'test product') | |
130 | + parent_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id) | |
131 | + child_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id, :parent_id => parent_cat.id) | |
132 | + ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent') | |
133 | + p = ent.products.new(:name => 'test product') | |
138 | 134 | p.product_category = child_cat |
139 | 135 | p.save! |
140 | 136 | |
... | ... | @@ -143,9 +139,9 @@ class ProductTest < Test::Unit::TestCase |
143 | 139 | end |
144 | 140 | |
145 | 141 | should 'change product categorization when product category changes' do |
146 | - cat1 = ProductCategory.create(:name => 'test cat 1', :environment => Environment.default) | |
147 | - cat2 = ProductCategory.create(:name => 'test cat 2', :environment => Environment.default) | |
148 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
142 | + cat1 = fast_create(ProductCategory, :name => 'test cat 1', :environment_id => Environment.default.id) | |
143 | + cat2 = fast_create(ProductCategory, :name => 'test cat 2', :environment_id => Environment.default.id) | |
144 | + ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent') | |
149 | 145 | p = ent.products.create!(:name => 'test product', :product_category => cat1) |
150 | 146 | |
151 | 147 | p.product_category = cat2 |
... | ... | @@ -155,25 +151,14 @@ class ProductTest < Test::Unit::TestCase |
155 | 151 | assert !ProductCategorization.find(:first, :conditions => {:product_id => p, :category_id => cat1}), 'must exclude the old category' |
156 | 152 | end |
157 | 153 | |
158 | - should 'remove categorization when product category is removed' do | |
159 | - cat = ProductCategory.create(:name => 'test cat', :environment => Environment.default) | |
160 | - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') | |
161 | - p = ent.products.create!(:name => 'test product', :product_category => cat) | |
162 | - | |
163 | - p.product_category = nil | |
164 | - p.save! | |
165 | - | |
166 | - assert !ProductCategorization.find(:first, :conditions => {:product_id => p, :category_id => cat}) | |
167 | - end | |
168 | - | |
169 | 154 | should 'respond to public? as its enterprise public?' do |
170 | - e1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1') | |
171 | - p1 = Product.create!(:name => 'test product 1', :enterprise => e1) | |
155 | + e1 = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') | |
156 | + p1 = fast_create(Product, :name => 'test product 1', :enterprise_id => e1.id, :product_category_id => @product_category.id) | |
172 | 157 | |
173 | 158 | assert p1.public? |
174 | 159 | |
175 | 160 | e1.public_profile = false |
176 | - e1.save! | |
161 | + e1.save!; p1.reload; | |
177 | 162 | |
178 | 163 | assert !p1.public? |
179 | 164 | end |
... | ... | @@ -193,16 +178,16 @@ class ProductTest < Test::Unit::TestCase |
193 | 178 | end |
194 | 179 | end |
195 | 180 | |
196 | - should 'sanitize name before validation' do | |
197 | - product = Product.new | |
181 | + should 'strip name with malformed HTML when sanitize' do | |
182 | + product = Product.new(:product_category => @product_category) | |
198 | 183 | product.name = "<h1 Bla </h1>" |
199 | 184 | product.valid? |
200 | 185 | |
201 | - assert product.errors.invalid?(:name) | |
186 | + assert_equal '', product.name | |
202 | 187 | end |
203 | 188 | |
204 | 189 | should 'escape malformed html tags' do |
205 | - product = Product.new | |
190 | + product = Product.new(:product_category => @product_category) | |
206 | 191 | product.name = "<h1 Malformed >> html >< tag" |
207 | 192 | product.description = "<h1 Malformed</h1>><<<a>> >> html >< tag" |
208 | 193 | product.valid? |
... | ... | @@ -211,4 +196,16 @@ class ProductTest < Test::Unit::TestCase |
211 | 196 | assert_no_match /[<>]/, product.description |
212 | 197 | end |
213 | 198 | |
199 | + should 'use name of category when has no name yet' do | |
200 | + product = Product.new(:product_category => @product_category) | |
201 | + assert product.valid? | |
202 | + assert_equal product.name, @product_category.name | |
203 | + end | |
204 | + | |
205 | + should 'not save without category' do | |
206 | + product = Product.new(:name => 'A product without category') | |
207 | + product.valid? | |
208 | + assert product.errors.invalid?(:product_category) | |
209 | + end | |
210 | + | |
214 | 211 | end | ... | ... |
test/unit/products_block_test.rb
... | ... | @@ -4,6 +4,7 @@ class ProductsBlockTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @block = ProductsBlock.new |
7 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
7 | 8 | end |
8 | 9 | attr_reader :block |
9 | 10 | |
... | ... | @@ -22,8 +23,8 @@ class ProductsBlockTest < ActiveSupport::TestCase |
22 | 23 | should "list owner products" do |
23 | 24 | |
24 | 25 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
25 | - enterprise.products.create!(:name => 'product one') | |
26 | - enterprise.products.create!(:name => 'product two') | |
26 | + enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
27 | + enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
27 | 28 | |
28 | 29 | block.expects(:products).returns(enterprise.products) |
29 | 30 | |
... | ... | @@ -38,8 +39,8 @@ class ProductsBlockTest < ActiveSupport::TestCase |
38 | 39 | |
39 | 40 | should 'point to all products in footer' do |
40 | 41 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
41 | - enterprise.products.create!(:name => 'product one') | |
42 | - enterprise.products.create!(:name => 'product two') | |
42 | + enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
43 | + enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
43 | 44 | |
44 | 45 | block.stubs(:owner).returns(enterprise) |
45 | 46 | |
... | ... | @@ -50,11 +51,11 @@ class ProductsBlockTest < ActiveSupport::TestCase |
50 | 51 | |
51 | 52 | should 'list 4 random products by default' do |
52 | 53 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
53 | - enterprise.products.create!(:name => 'product one') | |
54 | - enterprise.products.create!(:name => 'product two') | |
55 | - enterprise.products.create!(:name => 'product three') | |
56 | - enterprise.products.create!(:name => 'product four') | |
57 | - enterprise.products.create!(:name => 'product five') | |
54 | + enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
55 | + enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
56 | + enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
57 | + enterprise.products.create!(:name => 'product four', :product_category => @product_category) | |
58 | + enterprise.products.create!(:name => 'product five', :product_category => @product_category) | |
58 | 59 | |
59 | 60 | block.stubs(:owner).returns(enterprise) |
60 | 61 | |
... | ... | @@ -63,9 +64,9 @@ class ProductsBlockTest < ActiveSupport::TestCase |
63 | 64 | |
64 | 65 | should 'list all products if less than 4 by default' do |
65 | 66 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
66 | - enterprise.products.create!(:name => 'product one') | |
67 | - enterprise.products.create!(:name => 'product two') | |
68 | - enterprise.products.create!(:name => 'product three') | |
67 | + enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
68 | + enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
69 | + enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
69 | 70 | |
70 | 71 | block.stubs(:owner).returns(enterprise) |
71 | 72 | |
... | ... | @@ -76,11 +77,11 @@ class ProductsBlockTest < ActiveSupport::TestCase |
76 | 77 | should 'be able to set product_ids and have them listed' do |
77 | 78 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
78 | 79 | |
79 | - p1 = enterprise.products.create!(:name => 'product one') | |
80 | - p2 = enterprise.products.create!(:name => 'product two') | |
81 | - p3 = enterprise.products.create!(:name => 'product three') | |
82 | - p4 = enterprise.products.create!(:name => 'product four') | |
83 | - p5 = enterprise.products.create!(:name => 'product five') | |
80 | + p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
81 | + p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
82 | + p3 = enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
83 | + p4 = enterprise.products.create!(:name => 'product four', :product_category => @product_category) | |
84 | + p5 = enterprise.products.create!(:name => 'product five', :product_category => @product_category) | |
84 | 85 | |
85 | 86 | block.stubs(:owner).returns(enterprise) |
86 | 87 | |
... | ... | @@ -90,8 +91,8 @@ class ProductsBlockTest < ActiveSupport::TestCase |
90 | 91 | |
91 | 92 | should 'save product_ids' do |
92 | 93 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
93 | - p1 = enterprise.products.create!(:name => 'product one') | |
94 | - p2 = enterprise.products.create!(:name => 'product two') | |
94 | + p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
95 | + p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
95 | 96 | |
96 | 97 | block = ProductsBlock.new |
97 | 98 | enterprise.boxes.first.blocks << block |
... | ... | @@ -109,10 +110,10 @@ class ProductsBlockTest < ActiveSupport::TestCase |
109 | 110 | |
110 | 111 | should 'not repeat products' do |
111 | 112 | enterprise = Enterprise.create!(:name => 'test_enterprise', :identifier => 'test_enterprise') |
112 | - p1 = enterprise.products.create!(:name => 'product one') | |
113 | - p2 = enterprise.products.create!(:name => 'product two') | |
114 | - p3 = enterprise.products.create!(:name => 'product three') | |
115 | - p4 = enterprise.products.create!(:name => 'product four') | |
113 | + p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
114 | + p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
115 | + p3 = enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
116 | + p4 = enterprise.products.create!(:name => 'product four', :product_category => @product_category) | |
116 | 117 | |
117 | 118 | block = ProductsBlock.new |
118 | 119 | enterprise.boxes.first.blocks << block |
... | ... | @@ -126,8 +127,8 @@ class ProductsBlockTest < ActiveSupport::TestCase |
126 | 127 | should 'generate footer when enterprise has own hostname' do |
127 | 128 | enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') |
128 | 129 | enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save! |
129 | - enterprise.products.create!(:name => 'product one') | |
130 | - enterprise.products.create!(:name => 'product two') | |
130 | + enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
131 | + enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
131 | 132 | |
132 | 133 | block.stubs(:owner).returns(enterprise) |
133 | 134 | ... | ... |