From 7d200d67bfeb7c009be02acbced473303da6c1c2 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Wed, 15 Jan 2014 19:06:05 -0300 Subject: [PATCH] Rename enterprise variables to profile --- app/controllers/public/catalog_controller.rb | 2 +- plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb | 28 ++++++++++++++-------------- plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb | 5 ++--- plugins/shopping_cart/lib/shopping_cart_plugin.rb | 4 ++-- plugins/shopping_cart/public/buy.js | 2 +- plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb | 22 +++++++++++----------- plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb | 50 +++++++++++++++++++++++++------------------------- plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb | 10 +++++----- plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb | 4 ++-- 9 files changed, 63 insertions(+), 64 deletions(-) diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb index a800dea..25e4879 100644 --- a/app/controllers/public/catalog_controller.rb +++ b/app/controllers/public/catalog_controller.rb @@ -11,7 +11,7 @@ class CatalogController < PublicController protected def check_enterprise_and_environment - unless profile.kind_of?(Enterprise) && @profile.environment.enabled?('products_for_enterprises') + unless profile.enterprise? && @profile.environment.enabled?('products_for_enterprises') redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' end end diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb index 7b03be2..1e7b879 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb @@ -28,8 +28,8 @@ class ShoppingCartPluginController < PublicController def add product = find_product(params[:id]) - if product && enterprise = validate_same_enterprise(product) - self.cart = { :profile_id => enterprise.id, :items => {} } if self.cart.nil? + if product && profile = validate_same_profile(product) + self.cart = { :profile_id => profile.id, :items => {} } if self.cart.nil? self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? self.cart[:items][product.id] += 1 render :text => { @@ -38,7 +38,7 @@ class ShoppingCartPluginController < PublicController :products => [{ :id => product.id, :name => product.name, - :price => get_price(product, enterprise.environment), + :price => get_price(product, profile.environment), :description => product.description, :picture => product.default_image(:minor), :quantity => self.cart[:items][product.id] @@ -96,8 +96,8 @@ class ShoppingCartPluginController < PublicController def buy if validate_cart_presence @cart = cart - @enterprise = environment.enterprises.find(cart[:profile_id]) - @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) + @profile = environment.profiles.find(cart[:profile_id]) + @settings = Noosfero::Plugin::Settings.new(@profile, ShoppingCartPlugin) render :layout => false end end @@ -105,9 +105,9 @@ class ShoppingCartPluginController < PublicController def send_request register_order(params[:customer], self.cart[:items]) begin - enterprise = environment.enterprises.find(cart[:profile_id]) - ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) - ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) + profile = environment.profiles.find(cart[:profile_id]) + ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], profile, self.cart[:items], params[:delivery_option]) + ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], profile, self.cart[:items], params[:delivery_option]) self.cart = nil render :text => { :ok => true, @@ -168,8 +168,8 @@ class ShoppingCartPluginController < PublicController end def update_delivery_option - enterprise = environment.enterprises.find(cart[:profile_id]) - settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) + profile = environment.profiles.find(cart[:profile_id]) + settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) delivery_price = settings.delivery_options[params[:delivery_option]] delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) delivery.save(false) @@ -188,7 +188,7 @@ class ShoppingCartPluginController < PublicController private - def validate_same_enterprise(product) + def validate_same_profile(product) if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] render :text => { :ok => false, @@ -199,7 +199,7 @@ class ShoppingCartPluginController < PublicController }.to_json return nil end - product.enterprise + product.profile end def validate_cart_presence @@ -268,7 +268,7 @@ class ShoppingCartPluginController < PublicController new_items[id] = {:quantity => quantity, :price => price, :name => product.name} end ShoppingCartPlugin::PurchaseOrder.create!( - :seller => Enterprise.find(cart[:profile_id]), + :seller => environment.profiles.find(cart[:profile_id]), :customer => user, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, :products_list => new_items, @@ -325,7 +325,7 @@ class ShoppingCartPluginController < PublicController if product { :id => product.id, :name => product.name, - :price => get_price(product, product.enterprise.environment), + :price => get_price(product, product.profile.environment), :description => product.description, :picture => product.default_image(:minor), :quantity => quantity diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb index 1056a14..a44174c 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb @@ -1,7 +1,6 @@ -include ShoppingCartPlugin::CartHelper - class ShoppingCartPluginMyprofileController < MyProfileController - append_view_path File.join(File.dirname(__FILE__) + '/../views') + + include ShoppingCartPlugin::CartHelper def edit params[:settings] = treat_cart_options(params[:settings]) diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin.rb b/plugins/shopping_cart/lib/shopping_cart_plugin.rb index 59d1a65..c2acfaf 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin.rb @@ -23,8 +23,8 @@ class ShoppingCartPlugin < Noosfero::Plugin end def add_to_cart_button(item) - enterprise = item.enterprise - settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) + profile = item.profile + settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) if settings.enabled && item.available lambda { link_to(_('Add to basket'), "add:#{item.name}", diff --git a/plugins/shopping_cart/public/buy.js b/plugins/shopping_cart/public/buy.js index 950f9e0..4da3197 100644 --- a/plugins/shopping_cart/public/buy.js +++ b/plugins/shopping_cart/public/buy.js @@ -11,7 +11,7 @@ jQuery(document).ready(function(){ jQuery('#delivery_option').change(function(){ jQuery('#cboxLoadingGraphic').show(); me = this; - enterprise = jQuery(me).attr('data-profile-identifier'); + profile = jQuery(me).attr('data-profile-identifier'); option = jQuery(me).val(); jQuery.ajax({ url: '/plugin/shopping_cart/update_delivery_option', diff --git a/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb b/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb index 2455230..0192395 100644 --- a/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb +++ b/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb @@ -10,10 +10,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase @controller = ShoppingCartPluginController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new - @enterprise = fast_create(Enterprise) - @product = fast_create(Product, :profile_id => @enterprise.id) + @profile = fast_create(Enterprise) + @product = fast_create(Product, :profile_id => @profile.id) end - attr_reader :enterprise + attr_reader :profile attr_reader :product should 'force cookie expiration with explicit path for an empty cart' do @@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'just remove product if there are other products on cart' do - another_product = fast_create(Product, :profile_id => enterprise.id) + another_product = fast_create(Product, :profile_id => profile.id) get :add, :id => product.id get :add, :id => another_product.id @@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'clean the cart' do - another_product = fast_create(Product, :profile_id => enterprise.id) + another_product = fast_create(Product, :profile_id => profile.id) get :add, :id => product.id get :add, :id => another_product.id @@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'register order on send request' do - product1 = fast_create(Product, :profile_id => enterprise.id, :price => 1.99) - product2 = fast_create(Product, :profile_id => enterprise.id, :price => 2.23) - @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}}) + product1 = fast_create(Product, :profile_id => profile.id, :price => 1.99) + product2 = fast_create(Product, :profile_id => profile.id, :price => 2.23) + @controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1, product2.id => 2}}) assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do post :send_request, :customer => {:name => "Manuel", :email => "manuel@ceu.com"} @@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'register order on send request and not crash if product is not defined' do - product1 = fast_create(Product, :profile_id => enterprise.id) - @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1}}) + product1 = fast_create(Product, :profile_id => profile.id) + @controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1}}) assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do post :send_request, :customer => {:name => "Manuel", :email => "manuel@ceu.com"} @@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'clean the cart after placing the order' do - product1 = fast_create(Product, :profile_id => enterprise.id) + product1 = fast_create(Product, :profile_id => profile.id) post :add, :id => product1.id post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } assert !cart?, "cart expected to be empty!" diff --git a/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb b/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb index f91c071..0e2c4d7 100644 --- a/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb +++ b/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb @@ -5,17 +5,17 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase TIME_FORMAT = '%Y-%m-%d' def setup - @enterprise = fast_create(Enterprise) + @profile = fast_create(Enterprise) @admin = create_user('admin').person - @enterprise.add_admin(@admin) + @profile.add_admin(@admin) login_as(@admin.identifier) end - attr_reader :enterprise + attr_reader :profile should 'be able to enable shopping cart' do settings.enabled = false settings.save! - post :edit, :profile => enterprise.identifier, :settings => {:enabled => '1'} + post :edit, :profile => profile.identifier, :settings => {:enabled => '1'} assert settings.enabled end @@ -23,7 +23,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase should 'be able to disable shopping cart' do settings.enabled = true settings.save! - post :edit, :profile => enterprise.identifier, :settings => {:enabled => '0'} + post :edit, :profile => profile.identifier, :settings => {:enabled => '0'} assert !settings.enabled end @@ -31,7 +31,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase should 'be able to enable shopping cart delivery' do settings.delivery = false settings.save! - post :edit, :profile => enterprise.identifier, :settings => {:delivery => '1'} + post :edit, :profile => profile.identifier, :settings => {:delivery => '1'} assert settings.delivery end @@ -39,37 +39,37 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase should 'be able to disable shopping cart delivery' do settings.delivery = true settings.save! - post :edit, :profile => enterprise.identifier, :settings => {:delivery => '0'} + post :edit, :profile => profile.identifier, :settings => {:delivery => '0'} assert !settings.delivery end should 'be able to choose the delivery price' do price = 4.35 - post :edit, :profile => enterprise.identifier, :settings => {:delivery_price => price} + post :edit, :profile => profile.identifier, :settings => {:delivery_price => price} assert settings.delivery_price == price end should 'be able to choose delivery_options' do delivery_options = {:options => ['car', 'bike'], :prices => ['20', '5']} - post :edit, :profile => enterprise.identifier, :settings => {:delivery_options => delivery_options} + post :edit, :profile => profile.identifier, :settings => {:delivery_options => delivery_options} assert_equal '20', settings.delivery_options['car'] assert_equal '5', settings.delivery_options['bike'] end should 'filter the reports correctly' do - another_enterprise = fast_create(Enterprise) - po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) - po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::SHIPPED) - po3 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) + another_profile = fast_create(Enterprise) + po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) + po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::SHIPPED) + po3 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) po3.created_at = 1.year.ago po3.save! - po4 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => another_enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) + po4 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => another_profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) post :reports, - :profile => enterprise.identifier, + :profile => profile.identifier, :from => (Time.now - 1.day).strftime(TIME_FORMAT), :to => (Time.now + 1.day).strftime(TIME_FORMAT), :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED @@ -81,16 +81,16 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase end should 'group filtered orders products and quantities' do - p1 = fast_create(Product, :profile_id => enterprise.id, :price => 1, :name => 'p1') - p2 = fast_create(Product, :profile_id => enterprise.id, :price => 2, :name => 'p2') - p3 = fast_create(Product, :profile_id => enterprise.id, :price => 3) + p1 = fast_create(Product, :profile_id => profile.id, :price => 1, :name => 'p1') + p2 = fast_create(Product, :profile_id => profile.id, :price => 2, :name => 'p2') + p3 = fast_create(Product, :profile_id => profile.id, :price => 3) po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} - po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) - po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :products_list => po2_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) + po1 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :products_list => po1_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) + po2 = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :products_list => po2_products, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) post :reports, - :profile => enterprise.identifier, + :profile => profile.identifier, :from => (Time.now - 1.day).strftime(TIME_FORMAT), :to => (Time.now + 1.day).strftime(TIME_FORMAT), :filter_status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED @@ -107,10 +107,10 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase end should 'be able to update the order status' do - po = ShoppingCartPlugin::PurchaseOrder.create!(:seller => enterprise, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) + po = ShoppingCartPlugin::PurchaseOrder.create!(:seller => profile, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED) post :update_order_status, - :profile => enterprise.identifier, + :profile => profile.identifier, :order_id => po.id, :order_status => ShoppingCartPlugin::PurchaseOrder::Status::CONFIRMED po.reload @@ -120,7 +120,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase private def settings - @enterprise.reload - Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) + @profile.reload + Noosfero::Plugin::Settings.new(@profile, ShoppingCartPlugin) end end diff --git a/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb b/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb index c57d95f..a2d8312 100644 --- a/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb +++ b/plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb @@ -19,16 +19,16 @@ class ShoppingCartPluginTest < ActiveSupport::TestCase end should 'not add button if product unavailable' do - enterprise = fast_create(:enterprise) - product = fast_create(Product, :available => false, :profile_id => enterprise.id) - enterprise.stubs(:shopping_cart).returns(true) + profile = fast_create(:enterprise) + product = fast_create(Product, :available => false, :profile_id => profile.id) + profile.stubs(:shopping_cart).returns(true) assert_nil shopping_cart.add_to_cart_button(product) end should 'be disabled by default on the enterprise' do - enterprise = fast_create(Enterprise) - settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) + profile = fast_create(Enterprise) + settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) assert !settings.enabled end end diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb index e4ebb27..15ed699 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb @@ -6,7 +6,7 @@ <%= labelled_form_field('* ' + _("Name"), f.text_field(:name, :class => 'required') ) %> <%= labelled_form_field('* ' + _("Email"), f.text_field(:email, :class => 'required email') ) %> <%= labelled_form_field('* ' + _("Contact phone"), f.text_field(:contact_phone, :class => 'required') ) %> - <%= 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) %> + <%= 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) %> <%= labelled_form_field(_('Payment'), select_tag('customer[payment]', options_for_select([[_("Money"), :money],[_('shopping_cart|Check'), :check]]))) %> <%= labelled_form_field(s_('shopping_cart|Change'), text_field_tag('customer[change]')) %> @@ -24,7 +24,7 @@ <% end %> <% delivery_option = @settings.delivery_options.first && @settings.delivery_options.first.first %> - <%= items_table(@cart[:items], @enterprise, delivery_option) %> + <%= items_table(@cart[:items], @profile, delivery_option) %> <%= link_to '', '#', :onclick => "Cart.colorbox_close(this);", :class => 'cart-box-close icon-cancel' %> -- libgit2 0.21.2