Commit 7d200d67bfeb7c009be02acbced473303da6c1c2
1 parent
4d184a76
Exists in
master
and in
29 other branches
Rename enterprise variables to profile
Conflicts: plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
Showing
9 changed files
with
63 additions
and
64 deletions
Show diff stats
app/controllers/public/catalog_controller.rb
@@ -11,7 +11,7 @@ class CatalogController < PublicController | @@ -11,7 +11,7 @@ class CatalogController < PublicController | ||
11 | protected | 11 | protected |
12 | 12 | ||
13 | def check_enterprise_and_environment | 13 | def check_enterprise_and_environment |
14 | - unless profile.kind_of?(Enterprise) && @profile.environment.enabled?('products_for_enterprises') | 14 | + unless profile.enterprise? && @profile.environment.enabled?('products_for_enterprises') |
15 | redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' | 15 | redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' |
16 | end | 16 | end |
17 | end | 17 | end |
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
@@ -28,8 +28,8 @@ class ShoppingCartPluginController < PublicController | @@ -28,8 +28,8 @@ class ShoppingCartPluginController < PublicController | ||
28 | 28 | ||
29 | def add | 29 | def add |
30 | product = find_product(params[:id]) | 30 | product = find_product(params[:id]) |
31 | - if product && enterprise = validate_same_enterprise(product) | ||
32 | - self.cart = { :profile_id => enterprise.id, :items => {} } if self.cart.nil? | 31 | + if product && profile = validate_same_profile(product) |
32 | + self.cart = { :profile_id => profile.id, :items => {} } if self.cart.nil? | ||
33 | self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? | 33 | self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? |
34 | self.cart[:items][product.id] += 1 | 34 | self.cart[:items][product.id] += 1 |
35 | render :text => { | 35 | render :text => { |
@@ -38,7 +38,7 @@ class ShoppingCartPluginController < PublicController | @@ -38,7 +38,7 @@ class ShoppingCartPluginController < PublicController | ||
38 | :products => [{ | 38 | :products => [{ |
39 | :id => product.id, | 39 | :id => product.id, |
40 | :name => product.name, | 40 | :name => product.name, |
41 | - :price => get_price(product, enterprise.environment), | 41 | + :price => get_price(product, profile.environment), |
42 | :description => product.description, | 42 | :description => product.description, |
43 | :picture => product.default_image(:minor), | 43 | :picture => product.default_image(:minor), |
44 | :quantity => self.cart[:items][product.id] | 44 | :quantity => self.cart[:items][product.id] |
@@ -96,8 +96,8 @@ class ShoppingCartPluginController < PublicController | @@ -96,8 +96,8 @@ class ShoppingCartPluginController < PublicController | ||
96 | def buy | 96 | def buy |
97 | if validate_cart_presence | 97 | if validate_cart_presence |
98 | @cart = cart | 98 | @cart = cart |
99 | - @enterprise = environment.enterprises.find(cart[:profile_id]) | ||
100 | - @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) | 99 | + @profile = environment.profiles.find(cart[:profile_id]) |
100 | + @settings = Noosfero::Plugin::Settings.new(@profile, ShoppingCartPlugin) | ||
101 | render :layout => false | 101 | render :layout => false |
102 | end | 102 | end |
103 | end | 103 | end |
@@ -105,9 +105,9 @@ class ShoppingCartPluginController < PublicController | @@ -105,9 +105,9 @@ class ShoppingCartPluginController < PublicController | ||
105 | def send_request | 105 | def send_request |
106 | register_order(params[:customer], self.cart[:items]) | 106 | register_order(params[:customer], self.cart[:items]) |
107 | begin | 107 | begin |
108 | - enterprise = environment.enterprises.find(cart[:profile_id]) | ||
109 | - ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) | ||
110 | - ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) | 108 | + profile = environment.profiles.find(cart[:profile_id]) |
109 | + ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], profile, self.cart[:items], params[:delivery_option]) | ||
110 | + ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], profile, self.cart[:items], params[:delivery_option]) | ||
111 | self.cart = nil | 111 | self.cart = nil |
112 | render :text => { | 112 | render :text => { |
113 | :ok => true, | 113 | :ok => true, |
@@ -168,8 +168,8 @@ class ShoppingCartPluginController < PublicController | @@ -168,8 +168,8 @@ class ShoppingCartPluginController < PublicController | ||
168 | end | 168 | end |
169 | 169 | ||
170 | def update_delivery_option | 170 | def update_delivery_option |
171 | - enterprise = environment.enterprises.find(cart[:profile_id]) | ||
172 | - settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) | 171 | + profile = environment.profiles.find(cart[:profile_id]) |
172 | + settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) | ||
173 | delivery_price = settings.delivery_options[params[:delivery_option]] | 173 | delivery_price = settings.delivery_options[params[:delivery_option]] |
174 | delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) | 174 | delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) |
175 | delivery.save(false) | 175 | delivery.save(false) |
@@ -188,7 +188,7 @@ class ShoppingCartPluginController < PublicController | @@ -188,7 +188,7 @@ class ShoppingCartPluginController < PublicController | ||
188 | 188 | ||
189 | private | 189 | private |
190 | 190 | ||
191 | - def validate_same_enterprise(product) | 191 | + def validate_same_profile(product) |
192 | if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] | 192 | if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] |
193 | render :text => { | 193 | render :text => { |
194 | :ok => false, | 194 | :ok => false, |
@@ -199,7 +199,7 @@ class ShoppingCartPluginController < PublicController | @@ -199,7 +199,7 @@ class ShoppingCartPluginController < PublicController | ||
199 | }.to_json | 199 | }.to_json |
200 | return nil | 200 | return nil |
201 | end | 201 | end |
202 | - product.enterprise | 202 | + product.profile |
203 | end | 203 | end |
204 | 204 | ||
205 | def validate_cart_presence | 205 | def validate_cart_presence |
@@ -268,7 +268,7 @@ class ShoppingCartPluginController < PublicController | @@ -268,7 +268,7 @@ class ShoppingCartPluginController < PublicController | ||
268 | new_items[id] = {:quantity => quantity, :price => price, :name => product.name} | 268 | new_items[id] = {:quantity => quantity, :price => price, :name => product.name} |
269 | end | 269 | end |
270 | ShoppingCartPlugin::PurchaseOrder.create!( | 270 | ShoppingCartPlugin::PurchaseOrder.create!( |
271 | - :seller => Enterprise.find(cart[:profile_id]), | 271 | + :seller => environment.profiles.find(cart[:profile_id]), |
272 | :customer => user, | 272 | :customer => user, |
273 | :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, | 273 | :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, |
274 | :products_list => new_items, | 274 | :products_list => new_items, |
@@ -325,7 +325,7 @@ class ShoppingCartPluginController < PublicController | @@ -325,7 +325,7 @@ class ShoppingCartPluginController < PublicController | ||
325 | if product | 325 | if product |
326 | { :id => product.id, | 326 | { :id => product.id, |
327 | :name => product.name, | 327 | :name => product.name, |
328 | - :price => get_price(product, product.enterprise.environment), | 328 | + :price => get_price(product, product.profile.environment), |
329 | :description => product.description, | 329 | :description => product.description, |
330 | :picture => product.default_image(:minor), | 330 | :picture => product.default_image(:minor), |
331 | :quantity => quantity | 331 | :quantity => quantity |
plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
1 | -include ShoppingCartPlugin::CartHelper | ||
2 | - | ||
3 | class ShoppingCartPluginMyprofileController < MyProfileController | 1 | class ShoppingCartPluginMyprofileController < MyProfileController |
4 | - append_view_path File.join(File.dirname(__FILE__) + '/../views') | 2 | + |
3 | + include ShoppingCartPlugin::CartHelper | ||
5 | 4 | ||
6 | def edit | 5 | def edit |
7 | params[:settings] = treat_cart_options(params[:settings]) | 6 | params[:settings] = treat_cart_options(params[:settings]) |
plugins/shopping_cart/lib/shopping_cart_plugin.rb
@@ -23,8 +23,8 @@ class ShoppingCartPlugin < Noosfero::Plugin | @@ -23,8 +23,8 @@ class ShoppingCartPlugin < Noosfero::Plugin | ||
23 | end | 23 | end |
24 | 24 | ||
25 | def add_to_cart_button(item) | 25 | def add_to_cart_button(item) |
26 | - enterprise = item.enterprise | ||
27 | - settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) | 26 | + profile = item.profile |
27 | + settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) | ||
28 | if settings.enabled && item.available | 28 | if settings.enabled && item.available |
29 | lambda { | 29 | lambda { |
30 | link_to(_('Add to basket'), "add:#{item.name}", | 30 | link_to(_('Add to basket'), "add:#{item.name}", |
plugins/shopping_cart/public/buy.js
@@ -11,7 +11,7 @@ jQuery(document).ready(function(){ | @@ -11,7 +11,7 @@ jQuery(document).ready(function(){ | ||
11 | jQuery('#delivery_option').change(function(){ | 11 | jQuery('#delivery_option').change(function(){ |
12 | jQuery('#cboxLoadingGraphic').show(); | 12 | jQuery('#cboxLoadingGraphic').show(); |
13 | me = this; | 13 | me = this; |
14 | - enterprise = jQuery(me).attr('data-profile-identifier'); | 14 | + profile = jQuery(me).attr('data-profile-identifier'); |
15 | option = jQuery(me).val(); | 15 | option = jQuery(me).val(); |
16 | jQuery.ajax({ | 16 | jQuery.ajax({ |
17 | url: '/plugin/shopping_cart/update_delivery_option', | 17 | url: '/plugin/shopping_cart/update_delivery_option', |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -10,10 +10,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -10,10 +10,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
10 | @controller = ShoppingCartPluginController.new | 10 | @controller = ShoppingCartPluginController.new |
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
12 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
13 | - @enterprise = fast_create(Enterprise) | ||
14 | - @product = fast_create(Product, :profile_id => @enterprise.id) | 13 | + @profile = fast_create(Enterprise) |
14 | + @product = fast_create(Product, :profile_id => @profile.id) | ||
15 | end | 15 | end |
16 | - attr_reader :enterprise | 16 | + attr_reader :profile |
17 | attr_reader :product | 17 | attr_reader :product |
18 | 18 | ||
19 | should 'force cookie expiration with explicit path for an empty cart' do | 19 | should 'force cookie expiration with explicit path for an empty cart' do |
@@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
62 | end | 62 | end |
63 | 63 | ||
64 | should 'just remove product if there are other products on cart' do | 64 | should 'just remove product if there are other products on cart' do |
65 | - another_product = fast_create(Product, :profile_id => enterprise.id) | 65 | + another_product = fast_create(Product, :profile_id => profile.id) |
66 | get :add, :id => product.id | 66 | get :add, :id => product.id |
67 | get :add, :id => another_product.id | 67 | get :add, :id => another_product.id |
68 | 68 | ||
@@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
135 | end | 135 | end |
136 | 136 | ||
137 | should 'clean the cart' do | 137 | should 'clean the cart' do |
138 | - another_product = fast_create(Product, :profile_id => enterprise.id) | 138 | + another_product = fast_create(Product, :profile_id => profile.id) |
139 | get :add, :id => product.id | 139 | get :add, :id => product.id |
140 | get :add, :id => another_product.id | 140 | get :add, :id => another_product.id |
141 | 141 | ||
@@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
150 | end | 150 | end |
151 | 151 | ||
152 | should 'register order on send request' do | 152 | should 'register order on send request' do |
153 | - product1 = fast_create(Product, :profile_id => enterprise.id, :price => 1.99) | ||
154 | - product2 = fast_create(Product, :profile_id => enterprise.id, :price => 2.23) | ||
155 | - @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}}) | 153 | + product1 = fast_create(Product, :profile_id => profile.id, :price => 1.99) |
154 | + product2 = fast_create(Product, :profile_id => profile.id, :price => 2.23) | ||
155 | + @controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1, product2.id => 2}}) | ||
156 | assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do | 156 | assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do |
157 | post :send_request, | 157 | post :send_request, |
158 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} | 158 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} |
@@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
168 | end | 168 | end |
169 | 169 | ||
170 | should 'register order on send request and not crash if product is not defined' do | 170 | should 'register order on send request and not crash if product is not defined' do |
171 | - product1 = fast_create(Product, :profile_id => enterprise.id) | ||
172 | - @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1}}) | 171 | + product1 = fast_create(Product, :profile_id => profile.id) |
172 | + @controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1}}) | ||
173 | assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do | 173 | assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do |
174 | post :send_request, | 174 | post :send_request, |
175 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} | 175 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} |
@@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
181 | end | 181 | end |
182 | 182 | ||
183 | should 'clean the cart after placing the order' do | 183 | should 'clean the cart after placing the order' do |
184 | - product1 = fast_create(Product, :profile_id => enterprise.id) | 184 | + product1 = fast_create(Product, :profile_id => profile.id) |
185 | post :add, :id => product1.id | 185 | post :add, :id => product1.id |
186 | post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } | 186 | post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } |
187 | assert !cart?, "cart expected to be empty!" | 187 | assert !cart?, "cart expected to be empty!" |
plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
@@ -5,17 +5,17 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -5,17 +5,17 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
5 | TIME_FORMAT = '%Y-%m-%d' | 5 | TIME_FORMAT = '%Y-%m-%d' |
6 | 6 | ||
7 | def setup | 7 | def setup |
8 | - @enterprise = fast_create(Enterprise) | 8 | + @profile = fast_create(Enterprise) |
9 | @admin = create_user('admin').person | 9 | @admin = create_user('admin').person |
10 | - @enterprise.add_admin(@admin) | 10 | + @profile.add_admin(@admin) |
11 | login_as(@admin.identifier) | 11 | login_as(@admin.identifier) |
12 | end | 12 | end |
13 | - attr_reader :enterprise | 13 | + attr_reader :profile |
14 | 14 | ||
15 | should 'be able to enable shopping cart' do | 15 | should 'be able to enable shopping cart' do |
16 | settings.enabled = false | 16 | settings.enabled = false |
17 | settings.save! | 17 | settings.save! |
18 | - post :edit, :profile => enterprise.identifier, :settings => {:enabled => '1'} | 18 | + post :edit, :profile => profile.identifier, :settings => {:enabled => '1'} |
19 | 19 | ||
20 | assert settings.enabled | 20 | assert settings.enabled |
21 | end | 21 | end |
@@ -23,7 +23,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -23,7 +23,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
23 | should 'be able to disable shopping cart' do | 23 | should 'be able to disable shopping cart' do |
24 | settings.enabled = true | 24 | settings.enabled = true |
25 | settings.save! | 25 | settings.save! |
26 | - post :edit, :profile => enterprise.identifier, :settings => {:enabled => '0'} | 26 | + post :edit, :profile => profile.identifier, :settings => {:enabled => '0'} |
27 | 27 | ||
28 | assert !settings.enabled | 28 | assert !settings.enabled |
29 | end | 29 | end |
@@ -31,7 +31,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -31,7 +31,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
31 | should 'be able to enable shopping cart delivery' do | 31 | should 'be able to enable shopping cart delivery' do |
32 | settings.delivery = false | 32 | settings.delivery = false |
33 | settings.save! | 33 | settings.save! |
34 | - post :edit, :profile => enterprise.identifier, :settings => {:delivery => '1'} | 34 | + post :edit, :profile => profile.identifier, :settings => {:delivery => '1'} |
35 | 35 | ||
36 | assert settings.delivery | 36 | assert settings.delivery |
37 | end | 37 | end |
@@ -39,37 +39,37 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -39,37 +39,37 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
39 | should 'be able to disable shopping cart delivery' do | 39 | should 'be able to disable shopping cart delivery' do |
40 | settings.delivery = true | 40 | settings.delivery = true |
41 | settings.save! | 41 | settings.save! |
42 | - post :edit, :profile => enterprise.identifier, :settings => {:delivery => '0'} | 42 | + post :edit, :profile => profile.identifier, :settings => {:delivery => '0'} |
43 | 43 | ||
44 | assert !settings.delivery | 44 | assert !settings.delivery |
45 | end | 45 | end |
46 | 46 | ||
47 | should 'be able to choose the delivery price' do | 47 | should 'be able to choose the delivery price' do |
48 | price = 4.35 | 48 | price = 4.35 |
49 | - post :edit, :profile => enterprise.identifier, :settings => {:delivery_price => price} | 49 | + post :edit, :profile => profile.identifier, :settings => {:delivery_price => price} |
50 | 50 | ||
51 | assert settings.delivery_price == price | 51 | assert settings.delivery_price == price |
52 | end | 52 | end |
53 | 53 | ||
54 | should 'be able to choose delivery_options' do | 54 | should 'be able to choose delivery_options' do |
55 | delivery_options = {:options => ['car', 'bike'], :prices => ['20', '5']} | 55 | delivery_options = {:options => ['car', 'bike'], :prices => ['20', '5']} |
56 | - post :edit, :profile => enterprise.identifier, :settings => {:delivery_options => delivery_options} | 56 | + post :edit, :profile => profile.identifier, :settings => {:delivery_options => delivery_options} |
57 | 57 | ||
58 | assert_equal '20', settings.delivery_options['car'] | 58 | assert_equal '20', settings.delivery_options['car'] |
59 | assert_equal '5', settings.delivery_options['bike'] | 59 | assert_equal '5', settings.delivery_options['bike'] |
60 | end | 60 | end |
61 | 61 | ||
62 | should 'filter the reports correctly' do | 62 | should 'filter the reports correctly' do |
63 | - another_enterprise = fast_create(Enterprise) | ||
64 | - po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | ||
65 | - po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::SHIPPED) | ||
66 | - po3 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | 63 | + another_profile = fast_create(Enterprise) |
64 | + po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | ||
65 | + po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::SHIPPED) | ||
66 | + po3 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | ||
67 | po3.created_at = 1.year.ago | 67 | po3.created_at = 1.year.ago |
68 | po3.save! | 68 | po3.save! |
69 | - po4 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => another_enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | 69 | + po4 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => another_profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) |
70 | 70 | ||
71 | post :reports, | 71 | post :reports, |
72 | - :profile => enterprise.identifier, | 72 | + :profile => profile.identifier, |
73 | :from => (Time.now - 1.day).strftime(TIME_FORMAT), | 73 | :from => (Time.now - 1.day).strftime(TIME_FORMAT), |
74 | :to => (Time.now + 1.day).strftime(TIME_FORMAT), | 74 | :to => (Time.now + 1.day).strftime(TIME_FORMAT), |
75 | :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED | 75 | :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED |
@@ -81,16 +81,16 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -81,16 +81,16 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
81 | end | 81 | end |
82 | 82 | ||
83 | should 'group filtered orders products and quantities' do | 83 | should 'group filtered orders products and quantities' do |
84 | - p1 = fast_create(Product, :profile_id => enterprise.id, :price => 1, :name => 'p1') | ||
85 | - p2 = fast_create(Product, :profile_id => enterprise.id, :price => 2, :name => 'p2') | ||
86 | - p3 = fast_create(Product, :profile_id => enterprise.id, :price => 3) | 84 | + p1 = fast_create(Product, :profile_id => profile.id, :price => 1, :name => 'p1') |
85 | + p2 = fast_create(Product, :profile_id => profile.id, :price => 2, :name => 'p2') | ||
86 | + p3 = fast_create(Product, :profile_id => profile.id, :price => 3) | ||
87 | po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} | 87 | po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} |
88 | po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} | 88 | po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} |
89 | - po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | ||
90 | - po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po2_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | 89 | + po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) |
90 | + po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :products_list => po2_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | ||
91 | 91 | ||
92 | post :reports, | 92 | post :reports, |
93 | - :profile => enterprise.identifier, | 93 | + :profile => profile.identifier, |
94 | :from => (Time.now - 1.day).strftime(TIME_FORMAT), | 94 | :from => (Time.now - 1.day).strftime(TIME_FORMAT), |
95 | :to => (Time.now + 1.day).strftime(TIME_FORMAT), | 95 | :to => (Time.now + 1.day).strftime(TIME_FORMAT), |
96 | :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED | 96 | :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED |
@@ -107,10 +107,10 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -107,10 +107,10 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
107 | end | 107 | end |
108 | 108 | ||
109 | should 'be able to update the order status' do | 109 | should 'be able to update the order status' do |
110 | - po = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) | 110 | + po = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) |
111 | 111 | ||
112 | post :update_order_status, | 112 | post :update_order_status, |
113 | - :profile => enterprise.identifier, | 113 | + :profile => profile.identifier, |
114 | :order_id => po.id, | 114 | :order_id => po.id, |
115 | :order_status => ShoppingCartPlugin::PurchaseOrder::Status::CONFIRMED | 115 | :order_status => ShoppingCartPlugin::PurchaseOrder::Status::CONFIRMED |
116 | po.reload | 116 | po.reload |
@@ -120,7 +120,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | @@ -120,7 +120,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase | ||
120 | private | 120 | private |
121 | 121 | ||
122 | def settings | 122 | def settings |
123 | - @enterprise.reload | ||
124 | - Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) | 123 | + @profile.reload |
124 | + Noosfero::Plugin::Settings.new(@profile, ShoppingCartPlugin) | ||
125 | end | 125 | end |
126 | end | 126 | end |
plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb
@@ -19,16 +19,16 @@ class ShoppingCartPluginTest < ActiveSupport::TestCase | @@ -19,16 +19,16 @@ class ShoppingCartPluginTest < ActiveSupport::TestCase | ||
19 | end | 19 | end |
20 | 20 | ||
21 | should 'not add button if product unavailable' do | 21 | should 'not add button if product unavailable' do |
22 | - enterprise = fast_create(:enterprise) | ||
23 | - product = fast_create(Product, :available => false, :profile_id => enterprise.id) | ||
24 | - enterprise.stubs(:shopping_cart).returns(true) | 22 | + profile = fast_create(:enterprise) |
23 | + product = fast_create(Product, :available => false, :profile_id => profile.id) | ||
24 | + profile.stubs(:shopping_cart).returns(true) | ||
25 | 25 | ||
26 | assert_nil shopping_cart.add_to_cart_button(product) | 26 | assert_nil shopping_cart.add_to_cart_button(product) |
27 | end | 27 | end |
28 | 28 | ||
29 | should 'be disabled by default on the enterprise' do | 29 | should 'be disabled by default on the enterprise' do |
30 | - enterprise = fast_create(Enterprise) | ||
31 | - settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) | 30 | + profile = fast_create(Enterprise) |
31 | + settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) | ||
32 | assert !settings.enabled | 32 | assert !settings.enabled |
33 | end | 33 | end |
34 | end | 34 | end |
plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | <%= labelled_form_field('* ' + _("Name"), f.text_field(:name, :class => 'required') ) %> | 6 | <%= labelled_form_field('* ' + _("Name"), f.text_field(:name, :class => 'required') ) %> |
7 | <%= labelled_form_field('* ' + _("Email"), f.text_field(:email, :class => 'required email') ) %> | 7 | <%= labelled_form_field('* ' + _("Email"), f.text_field(:email, :class => 'required email') ) %> |
8 | <%= labelled_form_field('* ' + _("Contact phone"), f.text_field(:contact_phone, :class => 'required') ) %> | 8 | <%= labelled_form_field('* ' + _("Contact phone"), f.text_field(:contact_phone, :class => 'required') ) %> |
9 | - <%= labelled_form_field(_('Delivery option'), select_tag(:delivery_option, options_for_select(select_delivery_options(@settings.delivery_options, environment)), 'data-profile-identifier' => @enterprise.identifier)) unless !@settings.delivery || (@settings.free_delivery_price && get_total(@cart[:items]) >= @settings.free_delivery_price) %> | 9 | + <%= labelled_form_field(_('Delivery option'), select_tag(:delivery_option, options_for_select(select_delivery_options(@settings.delivery_options, environment)), 'data-profile-identifier' => @profile.identifier)) unless !@settings.delivery || (@settings.free_delivery_price && get_total(@cart[:items]) >= @settings.free_delivery_price) %> |
10 | <%= labelled_form_field(_('Payment'), select_tag('customer[payment]', options_for_select([[_("Money"), :money],[_('shopping_cart|Check'), :check]]))) %> | 10 | <%= labelled_form_field(_('Payment'), select_tag('customer[payment]', options_for_select([[_("Money"), :money],[_('shopping_cart|Check'), :check]]))) %> |
11 | <%= labelled_form_field(s_('shopping_cart|Change'), text_field_tag('customer[change]')) %> | 11 | <%= labelled_form_field(s_('shopping_cart|Change'), text_field_tag('customer[change]')) %> |
12 | </div> | 12 | </div> |
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | </div> | 24 | </div> |
25 | <% end %> | 25 | <% end %> |
26 | <% delivery_option = @settings.delivery_options.first && @settings.delivery_options.first.first %> | 26 | <% delivery_option = @settings.delivery_options.first && @settings.delivery_options.first.first %> |
27 | - <%= items_table(@cart[:items], @enterprise, delivery_option) %> | 27 | + <%= items_table(@cart[:items], @profile, delivery_option) %> |
28 | <%= link_to '', '#', :onclick => "Cart.colorbox_close(this);", :class => 'cart-box-close icon-cancel' %> | 28 | <%= link_to '', '#', :onclick => "Cart.colorbox_close(this);", :class => 'cart-box-close icon-cancel' %> |
29 | </div> | 29 | </div> |
30 | 30 |