diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb index 984db20..a84803b 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb @@ -8,39 +8,39 @@ class ShoppingCartPluginController < OrdersPluginController def get config = if cart.nil? - { :profile_id => params[:profile_id], - :has_products => false, - :visible => false, - :products => []} + { profile_id: params[:profile_id], + has_products: false, + visible: false, + products: []} else { - :profile_id => cart[:profile_id], - :profile_short_name => cart_profile.short_name, - :has_products => (cart[:items].keys.size > 0), - :visible => visible?, - :products => products, + profile_id: cart[:profile_id], + profile_short_name: cart_profile.short_name, + has_products: (cart[:items].keys.size > 0), + visible: visible?, + products: products, } end config[:has_previous_orders] = if cart_profile then previous_orders.first.present? else false end - render :text => config.to_json + render text: config.to_json end def add product = find_product(params[:id]) if product && (profile = validate_same_profile(product)) - self.cart = { :profile_id => profile.id, :items => {} } if self.cart.nil? + 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 => { - :ok => true, - :error => {:code => 0}, - :products => [{ - :id => product.id, - :name => product.name, - :price => get_price(product, profile.environment), - :description => product.description, - :picture => product.default_image(:minor), - :quantity => self.cart[:items][product.id] + render text: { + ok: true, + error: {code: 0}, + products: [{ + id: product.id, + name: product.name, + price: get_price(product, profile.environment), + description: product.description, + picture: product.default_image(:minor), + quantity: self.cart[:items][product.id] }] }.to_json end @@ -51,20 +51,20 @@ class ShoppingCartPluginController < OrdersPluginController if validate_cart_presence && validate_cart_has_product(id) self.cart[:items].delete(id) self.cart = nil if self.cart[:items].empty? - render :text => { - :ok => true, - :error => {:code => 0}, - :product_id => id + render text: { + ok: true, + error: {code: 0}, + product_id: id }.to_json end end def list if validate_cart_presence - render :text => { - :ok => true, - :error => {:code => 0}, - :products => products + render text: { + ok: true, + error: {code: 0}, + products: products }.to_json end end @@ -75,20 +75,20 @@ class ShoppingCartPluginController < OrdersPluginController if validate_cart_presence && validate_cart_has_product(id) && validate_item_quantity(quantity) product = Product.find(id) self.cart[:items][product.id] = quantity - render :text => { - :ok => true, - :error => {:code => 0}, - :product_id => id, - :quantity => quantity + render text: { + ok: true, + error: {code: 0}, + product_id: id, + quantity: quantity }.to_json end end def clean self.cart = nil - render :text => { - :ok => true, - :error => {:code => 0} + render text: { + ok: true, + error: {code: 0} }.to_json end @@ -121,7 +121,7 @@ class ShoppingCartPluginController < OrdersPluginController @profile = cart_profile @order = profile.sales.build consumer: user - @order.supplier_delivery = profile.delivery_methods.find session[:cart][:last_delivery_option_id] rescue nil + @order.supplier_delivery = profile.delivery_methods.where(id: session[:cart][:last_delivery_option_id]).first if repeat_order_id = self.cart[:repeat_order_id] repeat_order = cart_profile.orders.where(id: repeat_order_id).first @order.consumer_delivery_data = repeat_order.consumer_delivery_data if repeat_order @@ -146,23 +146,23 @@ class ShoppingCartPluginController < OrdersPluginController end def visibility - render :text => visible?.to_json + render text: visible?.to_json end def show begin self.cart[:visibility] = true - render :text => { - :ok => true, - :message => _('Basket displayed.'), - :error => {:code => 0} + render text: { + ok: true, + message: _('Basket displayed.'), + error: {code: 0} }.to_json rescue Exception => exception - render :text => { - :ok => false, - :error => { - :code => 7, - :message => exception.message + render text: { + ok: false, + error: { + code: 7, + message: exception.message } }.to_json end @@ -171,17 +171,17 @@ class ShoppingCartPluginController < OrdersPluginController def hide begin self.cart[:visibility] = false - render :text => { - :ok => true, - :message => _('Basket hidden.'), - :error => {:code => 0} + render text: { + ok: true, + message: _('Basket hidden.'), + error: {code: 0} }.to_json rescue Exception => exception - render :text => { - :ok => false, - :error => { - :code => 8, - :message => exception.message + render text: { + ok: false, + error: { + code: 8, + message: exception.message } }.to_json end @@ -189,7 +189,7 @@ class ShoppingCartPluginController < OrdersPluginController def update_supplier_delivery @profile = cart_profile - supplier_delivery = @profile.delivery_methods.find params[:order][:supplier_delivery_id] + supplier_delivery = @profile.delivery_methods.where(id: params[:order][:supplier_delivery_id]).first order = build_order self.cart[:items], supplier_delivery total_price = order.total_price render json: { @@ -210,11 +210,11 @@ class ShoppingCartPluginController < OrdersPluginController def validate_same_profile(product) if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] - render :text => { - :ok => false, - :error => { - :code => 1, - :message => _("Your basket contains items from '%{profile_name}'. Please empty the basket or checkout before adding items from here.") % {profile_name: cart_profile.short_name} + render text: { + ok: false, + error: { + code: 1, + message: _("Your basket contains items from '%{profile_name}'. Please empty the basket or checkout before adding items from here.") % {profile_name: cart_profile.short_name} } }.to_json return nil @@ -224,11 +224,11 @@ class ShoppingCartPluginController < OrdersPluginController def validate_cart_presence if self.cart.nil? - render :text => { - :ok => false, - :error => { - :code => 2, - :message => _("There is no basket.") + render text: { + ok: false, + error: { + code: 2, + message: _("There is no basket.") } }.to_json return false @@ -240,11 +240,11 @@ class ShoppingCartPluginController < OrdersPluginController begin product = Product.find(id) rescue ActiveRecord::RecordNotFound - render :text => { - :ok => false, - :error => { - :code => 3, - :message => _("This enterprise doesn't have this product.") + render text: { + ok: false, + error: { + code: 3, + message: _("This enterprise doesn't have this product.") } }.to_json return nil @@ -254,11 +254,11 @@ class ShoppingCartPluginController < OrdersPluginController def validate_cart_has_product(id) if !self.cart[:items].has_key?(id) - render :text => { - :ok => false, - :error => { - :code => 4, - :message => _("The basket doesn't have this product.") + render text: { + ok: false, + error: { + code: 4, + message: _("The basket doesn't have this product.") } }.to_json return false @@ -268,11 +268,11 @@ class ShoppingCartPluginController < OrdersPluginController def validate_item_quantity(quantity) if quantity.to_i < 1 - render :text => { - :ok => false, - :error => { - :code => 5, - :message => _("Invalid quantity.") + render text: { + ok: false, + error: { + code: 5, + message: _("Invalid quantity.") } }.to_json return false @@ -284,12 +284,12 @@ class ShoppingCartPluginController < OrdersPluginController products_list = {}; items.each do |id, quantity| product = Product.find(id) price = product.price || 0 - products_list[id] = {:quantity => quantity, :price => price, :name => product.name} + products_list[id] = {quantity: quantity, price: price, name: product.name} end order = OrdersPlugin::Sale.new order.profile = environment.profiles.find(cart[:profile_id]) - order.supplier_delivery = profile.delivery_methods.find params[:order][:supplier_delivery_id] + order.supplier_delivery = profile.delivery_methods.where(id: params[:order][:supplier_delivery_id]).first order.session_id = session_id unless user order.consumer = user order.source = 'shopping_cart_plugin' @@ -330,11 +330,11 @@ class ShoppingCartPluginController < OrdersPluginController after_filter :save_cookie def save_cookie if @cart.nil? - cookies.delete(cookie_key, :path => '/plugin/shopping_cart') + cookies.delete(cookie_key, path: '/plugin/shopping_cart') else cookies[cookie_key] = { - :value => Base64.encode64(@cart.to_yaml), - :path => "/plugin/shopping_cart" + value: Base64.encode64(@cart.to_yaml), + path: "/plugin/shopping_cart" } end end @@ -351,20 +351,20 @@ class ShoppingCartPluginController < OrdersPluginController self.cart[:items].collect do |id, quantity| product = Product.find_by_id(id) if product - { :id => product.id, - :name => product.name, - :price => get_price(product, product.profile.environment), - :description => product.description, - :picture => product.default_image(:minor), - :quantity => quantity + { id: product.id, + name: product.name, + price: get_price(product, product.profile.environment), + description: product.description, + picture: product.default_image(:minor), + quantity: quantity } else - { :id => id, - :name => _('Undefined product'), - :price => 0, - :description => _('Wrong product id'), - :picture => '', - :quantity => quantity + { id: id, + name: _('Undefined product'), + price: 0, + description: _('Wrong product id'), + picture: '', + quantity: quantity } end end 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 4ba4e5a..2fb2ca9 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb @@ -5,13 +5,8 @@ class ShoppingCartPluginMyprofileController < MyProfileController def edit params[:settings] = treat_cart_options(params[:settings]) @settings = profile.shopping_cart_settings params[:settings] || {} - respond_to do |format| - format.js do - if request.post? - @success = @settings.save! - end - end - format.html + if request.post? + @success = @settings.save! end end diff --git a/plugins/shopping_cart/delivery_admin.feature b/plugins/shopping_cart/delivery_admin.feature deleted file mode 100644 index 9101a40..0000000 --- a/plugins/shopping_cart/delivery_admin.feature +++ /dev/null @@ -1,81 +0,0 @@ -Feature: delivery administration - As an enterprise's administrator - I want to create delivery methods - In order to allow my customer to choose which delivery they want - - Background: - Given "ShoppingCart" plugin is enabled - And "Delivery" plugin is enabled - And the following users - | login | name | - | moe | Moe | - And the following enterprise - | identifier | name | owner | - | moes-tavern | Moes Tavern | moe | - And the shopping basket is enabled on "Moes Tavern" - And "Moe" is admin of "Moes Tavern" - And I am logged in as "moe" - And I go to moes-tavern's control panel - - @selenium - Scenario: enable delivery - Given I follow "Shopping basket" - When I check "Enable shopping basket" - Then I should see "Deliveries or pickups" - - @selenium - Scenario: disable delivery - Given I follow "Shopping basket" - When I uncheck "Enable shopping basket" - Then I should not see "Deliveries or pickups" - - @selenium - Scenario: create new deliver - Given I follow "Shopping basket" - And I check "Enable shopping basket" - And I follow "New delivery or pickup" - And I select "Deliver" from "Type" - And I fill in "Name" with "Bike" - And I fill in "Description" with "Beers delivered with my old bike." - And I fill in "Fixed cost" with "8.00" - And I fill in "Order's minimum price for free delivery" with "35.50" - When I press "Add" - Then I should see "Bike" within ".delivery-method" - - @selenium - Scenario: create new pickup - Given I follow "Shopping basket" - And I check "Enable shopping basket" - And I follow "New delivery or pickup" - And I select "Pickup" from "Type" - And I fill in "Name" with "Bar" - And I fill in "Description" with "Come to my bar and pick it yourself." - And I fill in "Fixed cost" with "0.00" - When I press "Add" - Then I should see "Bar" - - @selenium - Scenario: remove delivery - Given I follow "Shopping basket" - And I check "Enable shopping basket" - And I follow "New delivery or pickup" - And I fill in "Name" with "Bike" - When I press "Add" - Then I should see "Bike" - And I follow "Remove" within ".delivery-method" - When I confirm the browser dialog - Then I should see "Bike" - - @selenium - Scenario: edit delivery - Given I follow "Shopping basket" - And I check "Enable shopping basket" - And I follow "New delivery or pickup" - And I fill in "Name" with "Bike" - When I press "Add" - Then I should see "Bike" - And I follow "Edit" within ".delivery-method" - And I fill in "Name" with "Car" - When I press "Save" - Then I should not see "Bike" - Then I should see "Car" diff --git a/plugins/shopping_cart/delivery_client.feature b/plugins/shopping_cart/delivery_client.feature deleted file mode 100644 index 31fb8f0..0000000 --- a/plugins/shopping_cart/delivery_client.feature +++ /dev/null @@ -1,77 +0,0 @@ -Feature: delivery client - As an enterprise's client - I want to choose the delivery method - In order to receive my procucts properly - - Background: - Given "ShoppingCart" plugin is enabled - And "Delivery" plugin is enabled - And the following users - | login | name | email | - | moe | Moe | moe@springfield.com | - | homer | Homer | homer@springfield.com | - And the following enterprise - | identifier | name | owner | - | moes-tavern | Moes Tavern | moe | - And the shopping basket is enabled on "Moes Tavern" - And the following product_categories - | name | - | Beer | - | Snacks | - And the following products - | owner | category | name | price | - | moes-tavern | beer | Duff | 3.00 | - | moes-tavern | snacks | French fries | 7.00 | - And "moes-tavern" has the following delivery methods - | delivery_type | name | description | fixed_cost | free_over_price | - | deliver | Bike | My good old bike. | 8.00 | 10.00 | - | pickup | Bar | Come to my bar and drink it! | 0.00 | 0.00 | - And feature "products_for_enterprises" is enabled on environment - And I am logged in as "homer" - And I go to moes-tavern's products page - - @selenium - Scenario: choose deliver method for purchase - Given I follow "Add to basket" - And I follow "Add to basket" - And I should see "Show basket" - And I follow "Show basket" - And I follow "Shopping checkout" - And I fill in "Contact phone" with "123456789" - When I select "Bike ($8.00)" from "Option" - Then I should see "My good old bike." within ".instructions" - And I should see "Address" - And I should see "Bike" within "#delivery-name" - And I should see "8.00" within "#delivery-price" - - @selenium - Scenario: choose pickup method for purchase - Given I follow "Add to basket" - And I follow "Add to basket" - And I should see "Show basket" - And I follow "Show basket" - And I follow "Shopping checkout" - And I fill in "Contact phone" with "123456789" - When I select "Bar" from "Option" - Then I should see "Come to my bar and drink it!" within ".instructions" - And I should not see "Address" - And I should see "Bar" within "#delivery-name" - And I should see "0.00" within "#delivery-price" - - @selenium - Scenario: gets free delivery due to free over price - Given I follow "Add to basket" - And I follow "Add to basket" - And I follow "Add to basket" - And I follow "Add to basket" - And I follow "Add to basket" - And I follow "Add to basket" - And I should see "Show basket" - And I follow "Show basket" - And I follow "Shopping checkout" - And I fill in "Contact phone" with "123456789" - When I select "Bike ($8.00)" from "Option" - Then I should see "My good old bike." within ".instructions" - And I should see "Address" - And I should see "Bike" within "#delivery-name" - And I should see "0.00" within "#delivery-price" diff --git a/plugins/shopping_cart/features/delivery_admin.feature b/plugins/shopping_cart/features/delivery_admin.feature new file mode 100644 index 0000000..9101a40 --- /dev/null +++ b/plugins/shopping_cart/features/delivery_admin.feature @@ -0,0 +1,81 @@ +Feature: delivery administration + As an enterprise's administrator + I want to create delivery methods + In order to allow my customer to choose which delivery they want + + Background: + Given "ShoppingCart" plugin is enabled + And "Delivery" plugin is enabled + And the following users + | login | name | + | moe | Moe | + And the following enterprise + | identifier | name | owner | + | moes-tavern | Moes Tavern | moe | + And the shopping basket is enabled on "Moes Tavern" + And "Moe" is admin of "Moes Tavern" + And I am logged in as "moe" + And I go to moes-tavern's control panel + + @selenium + Scenario: enable delivery + Given I follow "Shopping basket" + When I check "Enable shopping basket" + Then I should see "Deliveries or pickups" + + @selenium + Scenario: disable delivery + Given I follow "Shopping basket" + When I uncheck "Enable shopping basket" + Then I should not see "Deliveries or pickups" + + @selenium + Scenario: create new deliver + Given I follow "Shopping basket" + And I check "Enable shopping basket" + And I follow "New delivery or pickup" + And I select "Deliver" from "Type" + And I fill in "Name" with "Bike" + And I fill in "Description" with "Beers delivered with my old bike." + And I fill in "Fixed cost" with "8.00" + And I fill in "Order's minimum price for free delivery" with "35.50" + When I press "Add" + Then I should see "Bike" within ".delivery-method" + + @selenium + Scenario: create new pickup + Given I follow "Shopping basket" + And I check "Enable shopping basket" + And I follow "New delivery or pickup" + And I select "Pickup" from "Type" + And I fill in "Name" with "Bar" + And I fill in "Description" with "Come to my bar and pick it yourself." + And I fill in "Fixed cost" with "0.00" + When I press "Add" + Then I should see "Bar" + + @selenium + Scenario: remove delivery + Given I follow "Shopping basket" + And I check "Enable shopping basket" + And I follow "New delivery or pickup" + And I fill in "Name" with "Bike" + When I press "Add" + Then I should see "Bike" + And I follow "Remove" within ".delivery-method" + When I confirm the browser dialog + Then I should see "Bike" + + @selenium + Scenario: edit delivery + Given I follow "Shopping basket" + And I check "Enable shopping basket" + And I follow "New delivery or pickup" + And I fill in "Name" with "Bike" + When I press "Add" + Then I should see "Bike" + And I follow "Edit" within ".delivery-method" + And I fill in "Name" with "Car" + When I press "Save" + Then I should not see "Bike" + Then I should see "Car" diff --git a/plugins/shopping_cart/features/delivery_client.feature b/plugins/shopping_cart/features/delivery_client.feature new file mode 100644 index 0000000..31fb8f0 --- /dev/null +++ b/plugins/shopping_cart/features/delivery_client.feature @@ -0,0 +1,77 @@ +Feature: delivery client + As an enterprise's client + I want to choose the delivery method + In order to receive my procucts properly + + Background: + Given "ShoppingCart" plugin is enabled + And "Delivery" plugin is enabled + And the following users + | login | name | email | + | moe | Moe | moe@springfield.com | + | homer | Homer | homer@springfield.com | + And the following enterprise + | identifier | name | owner | + | moes-tavern | Moes Tavern | moe | + And the shopping basket is enabled on "Moes Tavern" + And the following product_categories + | name | + | Beer | + | Snacks | + And the following products + | owner | category | name | price | + | moes-tavern | beer | Duff | 3.00 | + | moes-tavern | snacks | French fries | 7.00 | + And "moes-tavern" has the following delivery methods + | delivery_type | name | description | fixed_cost | free_over_price | + | deliver | Bike | My good old bike. | 8.00 | 10.00 | + | pickup | Bar | Come to my bar and drink it! | 0.00 | 0.00 | + And feature "products_for_enterprises" is enabled on environment + And I am logged in as "homer" + And I go to moes-tavern's products page + + @selenium + Scenario: choose deliver method for purchase + Given I follow "Add to basket" + And I follow "Add to basket" + And I should see "Show basket" + And I follow "Show basket" + And I follow "Shopping checkout" + And I fill in "Contact phone" with "123456789" + When I select "Bike ($8.00)" from "Option" + Then I should see "My good old bike." within ".instructions" + And I should see "Address" + And I should see "Bike" within "#delivery-name" + And I should see "8.00" within "#delivery-price" + + @selenium + Scenario: choose pickup method for purchase + Given I follow "Add to basket" + And I follow "Add to basket" + And I should see "Show basket" + And I follow "Show basket" + And I follow "Shopping checkout" + And I fill in "Contact phone" with "123456789" + When I select "Bar" from "Option" + Then I should see "Come to my bar and drink it!" within ".instructions" + And I should not see "Address" + And I should see "Bar" within "#delivery-name" + And I should see "0.00" within "#delivery-price" + + @selenium + Scenario: gets free delivery due to free over price + Given I follow "Add to basket" + And I follow "Add to basket" + And I follow "Add to basket" + And I follow "Add to basket" + And I follow "Add to basket" + And I follow "Add to basket" + And I should see "Show basket" + And I follow "Show basket" + And I follow "Shopping checkout" + And I fill in "Contact phone" with "123456789" + When I select "Bike ($8.00)" from "Option" + Then I should see "My good old bike." within ".instructions" + And I should see "Address" + And I should see "Bike" within "#delivery-name" + And I should see "0.00" within "#delivery-price" diff --git a/plugins/shopping_cart/features/step_definitions/orders_steps.rb b/plugins/shopping_cart/features/step_definitions/orders_steps.rb index dcfda78..c73b05a 100644 --- a/plugins/shopping_cart/features/step_definitions/orders_steps.rb +++ b/plugins/shopping_cart/features/step_definitions/orders_steps.rb @@ -1,11 +1,3 @@ -Given /^"([^""]*)" has the following delivery methods$/ do |name, table| - enterprise = Enterprise.find_by_name(name) || Enterprise[name] - table.hashes.map{|item| item.dup}.each do |item| - delivery_method = enterprise.delivery_methods.build - delivery_method.update_attributes(item) - end -end - Given /^the following purchase from "([^""]*)" on "([^""]*)" that is "([^""]*)"$/ do |consumer_identifier, enterprise_identifier, status, table| consumer = Person.find_by_name(consumer_identifier) || Person[consumer_identifier] enterprise = Enterprise.find_by_name(enterprise_identifier) || Enterprise[enterprise_identifier] diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb index df3e5ed..53f0377 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb @@ -59,7 +59,7 @@ module ShoppingCartPlugin::CartHelper @order end - def items_table(items, profile, delivery_method = nil, by_mail = false) + def items_table(items, delivery_method = nil, by_mail = false) # partial key needed in mailer context render partial: 'shopping_cart_plugin/items', locals: {order: build_order(items, delivery_method), by_mail: by_mail} end 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 b82fb3d..d96b869 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 @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' -require File.dirname(__FILE__) + '/../../controllers/shopping_cart_plugin_controller' +require 'test_helper' +require_relative '../../controllers/shopping_cart_plugin_controller' # Re-raise errors caught by the controller. class ShoppingCartPluginController; def rescue_action(e) raise e end; end @@ -12,7 +12,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new @profile = fast_create(Enterprise) @profile.contact_email = 'enterprise@noosfero.org';@profile.save - @product = fast_create(Product, :profile_id => @profile.id) + @product = fast_create(Product, profile_id: @profile.id) end attr_reader :profile attr_reader :product @@ -23,22 +23,22 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'add a new product to cart' do - get :add, :id => product.id + get :add, id: product.id assert product_in_cart?(product) assert_equal 1, product_quantity(product) end should 'grow quantity through add' do - get :add, :id => product.id + get :add, id: product.id assert_equal 1, product_quantity(product) - get :add, :id => product.id + get :add, id: product.id assert_equal 2, product_quantity(product) end should 'not add product to cart if it does not exists' do - assert_nothing_raised { get :add, :id => 9999 } + assert_nothing_raised { get :add, id: 9999 } refute product_in_cart?(product) refute response_ok? @@ -46,10 +46,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'remove cart if the product being removed is the last one' do - get :add, :id => product.id + get :add, id: product.id assert cart? - get :remove, :id => product.id + get :remove, id: product.id refute cart? end @@ -57,25 +57,25 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase instantiate_cart refute cart? - assert_nothing_raised { get :remove, :id => 9999 } + assert_nothing_raised { get :remove, id: 9999 } refute response_ok? assert_equal 2, reponse_error_code end should 'just remove product if there are other products on cart' do - another_product = fast_create(Product, :profile_id => profile.id) - get :add, :id => product.id - get :add, :id => another_product.id + another_product = fast_create(Product, profile_id: profile.id) + get :add, id: product.id + get :add, id: another_product.id - get :remove, :id => product.id + get :remove, id: product.id assert cart? refute product_in_cart?(product) end should 'not try to remove a product that is not in the cart' do - get :add, :id => product.id + get :add, id: product.id assert cart? - assert_nothing_raised { get :remove, :id => 9999 } + assert_nothing_raised { get :remove, id: 9999 } refute response_ok? assert_equal 4, reponse_error_code @@ -91,17 +91,17 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'list products without errors' do - get :add, :id => product.id + get :add, id: product.id assert_nothing_raised { get :list } assert response_ok? end should 'update the quantity of a product' do - get :add, :id => product.id + get :add, id: product.id assert_equal 1, product_quantity(product) - get :update_quantity, :id => product.id, :quantity => 3 + get :update_quantity, id: product.id, quantity: 3 assert_equal 3, product_quantity(product) end @@ -109,36 +109,36 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase instantiate_cart refute cart? - assert_nothing_raised { get :update_quantity, :id => 9999, :quantity => 3 } + assert_nothing_raised { get :update_quantity, id: 9999, quantity: 3 } refute response_ok? assert_equal 2, reponse_error_code end should 'not try to update the quantity of a product that is not in the cart' do - get :add, :id => product.id + get :add, id: product.id assert cart? - assert_nothing_raised { get :update_quantity, :id => 9999, :quantity => 3 } + assert_nothing_raised { get :update_quantity, id: 9999, quantity: 3 } refute response_ok? assert_equal 4, reponse_error_code end should 'not update the quantity of a product with a invalid value' do - get :add, :id => product.id + get :add, id: product.id - assert_nothing_raised { get :update_quantity, :id => product.id, :quantity => -1} + assert_nothing_raised { get :update_quantity, id: product.id, quantity: -1} refute response_ok? assert_equal 5, reponse_error_code - assert_nothing_raised { get :update_quantity, :id => product.id, :quantity => 'asdf'} + assert_nothing_raised { get :update_quantity, id: product.id, quantity: 'asdf'} refute response_ok? assert_equal 5, reponse_error_code end should 'clean the cart' do - another_product = fast_create(Product, :profile_id => profile.id) - get :add, :id => product.id - get :add, :id => another_product.id + another_product = fast_create(Product, profile_id: profile.id) + get :add, id: product.id + get :add, id: another_product.id assert_nothing_raised { get :clean } refute cart? @@ -151,12 +151,11 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'register order on send request' do - 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}}) + 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 'OrdersPlugin::Order.count', 1 do - post :send_request, - :customer => {:name => "Manuel", :email => "manuel@ceu.com"} + xhr :post, :send_request, order: {consumer_data: {name: "Manuel", email: "manuel@ceu.com"}} end order = OrdersPlugin::Order.last @@ -165,15 +164,14 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase assert_equal 1, order.products_list[product1.id][:quantity] assert_equal 2.23, order.products_list[product2.id][:price] assert_equal 2, order.products_list[product2.id][:quantity] - assert_equal 'confirmed', order.status + assert_equal 'ordered', order.status end should 'register order on send request and not crash if product is not defined' do - product1 = fast_create(Product, :profile_id => profile.id) - @controller.stubs(:cart).returns({ :profile_id => profile.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 'OrdersPlugin::Order.count', 1 do - post :send_request, - :customer => {:name => "Manuel", :email => "manuel@ceu.com"} + xhr :post, :send_request, order: {consumer_data: {name: "Manuel", email: "manuel@ceu.com"}} end order = OrdersPlugin::Order.last @@ -182,16 +180,15 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'clean the cart after placing the order' do - product1 = fast_create(Product, :profile_id => profile.id) - post :add, :id => product1.id - post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } + product1 = fast_create(Product, profile_id: profile.id) + post :add, id: product1.id + xhr :post, :send_request, order: {consumer_data: {name: "Manuel", email: "manuel@ceu.com"}} refute cart?, "cart expected to be empty!" end should 'not allow buy without any cart' do get :buy - refute json_response[:ok] - assert_equal 2, json_response['error']['code'] + assert_response :redirect end private @@ -225,8 +222,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase # temporary hack...if I don't do this the session stays as an Array instead # of a TestSession def instantiate_cart - get :add, :id => product.id - get :remove, :id => product.id + get :add, id: product.id + get :remove, id: product.id end end 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 7788882..4ac568a 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 @@ -1,9 +1,7 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' +require 'test_helper' class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase - TIME_FORMAT = '%Y-%m-%d' - def setup @profile = fast_create(Enterprise) @admin = create_user('admin').person @@ -13,115 +11,23 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase attr_reader :profile should 'be able to enable shopping cart' do - settings.enabled = false - settings.save! - post :edit, :profile => profile.identifier, :settings => {:enabled => '1'} - - assert settings.enabled - end - - should 'be able to disable shopping cart' do - settings.enabled = true - settings.save! - post :edit, :profile => profile.identifier, :settings => {:enabled => '0'} - - refute settings.enabled - end + profile.shopping_cart_settings.enabled = false + profile.shopping_cart_settings.save! - should 'be able to enable shopping cart delivery' do - settings.delivery = false - settings.save! - post :edit, :profile => profile.identifier, :settings => {:delivery => '1'} + post :edit, profile: profile.identifier, settings: {enabled: '1'} + profile.reload - assert settings.delivery + assert profile.shopping_cart_settings.enabled end - should 'be able to disable shopping cart delivery' do - settings.delivery = true - settings.save! - post :edit, :profile => profile.identifier, :settings => {:delivery => '0'} - - refute settings.delivery - end - - should 'be able to choose the delivery price' do - price = 4.35 - post :edit, :profile => profile.identifier, :settings => {:delivery_price => price} - - assert settings.delivery_price == price.to_s - end - - # FIXME - should 'be able to choose delivery_options' do - delivery_options = {:options => ['car', 'bike'], :prices => ['20', '5']} - 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_profile = fast_create(Enterprise) - po1 = OrdersPlugin::Sale.create! :profile => profile, :status => 'confirmed' - po2 = OrdersPlugin::Sale.create! :profile => profile, :status => 'shipped' - po3 = OrdersPlugin::Sale.create! :profile => profile, :status => 'confirmed' - po3.created_at = 1.year.ago - po3.save! - po4 = OrdersPlugin::Sale.create! :profile => another_profile, :status => 'confirmed' - - post :reports, - :profile => profile.identifier, - :from => (Time.now - 1.day).strftime(TIME_FORMAT), - :to => (Time.now + 1.day).strftime(TIME_FORMAT), - :filter_status => 'confirmed' - - assert_includes assigns(:orders), po1 - assert_not_includes assigns(:orders), po2 - assert_not_includes assigns(:orders), po3 - assert_not_includes assigns(:orders), po4 - end - - should 'group filtered orders products and quantities' do - 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 = OrdersPlugin::Sale.create! :profile => profile, :products_list => po1_products, :status => 'confirmed' - po2 = OrdersPlugin::Sale.create! :profile => profile, :products_list => po2_products, :status => 'confirmed' - - post :reports, - :profile => profile.identifier, - :from => (Time.now - 1.day).strftime(TIME_FORMAT), - :to => (Time.now + 1.day).strftime(TIME_FORMAT), - :filter_status => 'confirmed' - - lineitem1 = ShoppingCartPlugin::LineItem.new(p1.id, p1.name) - lineitem1.quantity = 1 - lineitem2 = ShoppingCartPlugin::LineItem.new(p2.id, p2.name) - lineitem2.quantity = 3 - lineitem3 = ShoppingCartPlugin::LineItem.new(p3.id, p3.name) - lineitem3.quantity = 2 - hash = {p1.id => lineitem1, p2.id => lineitem2, p3.id => lineitem3} - - assert_equal hash, assigns(:products) - end + should 'be able to disable shopping cart' do + profile.shopping_cart_settings.enabled = true + profile.shopping_cart_settings.save! - should 'be able to update the order status' do - po = OrdersPlugin::Sale.create!(:profile => profile, :status => 'confirmed') + post :edit, profile: profile.identifier, settings: {enabled: '0'} + profile.reload - post :update_order_status, - :profile => profile.identifier, - :order_id => po.id, - :order_status => 'confirmed' - po.reload - assert_equal 'confirmed', po.status + refute profile.shopping_cart_settings.enabled end - private - - def settings - @profile.reload - profile.shopping_cart_settings - end end diff --git a/plugins/shopping_cart/test/unit/shopping_cart_plugin/cart_helper_test.rb b/plugins/shopping_cart/test/unit/shopping_cart_plugin/cart_helper_test.rb index c65a1e2..0e034fb 100644 --- a/plugins/shopping_cart/test/unit/shopping_cart_plugin/cart_helper_test.rb +++ b/plugins/shopping_cart/test/unit/shopping_cart_plugin/cart_helper_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require 'test_helper' class ShoppingCartPlugin::CartHelperTest < ActiveSupport::TestCase @@ -41,19 +41,4 @@ class ShoppingCartPlugin::CartHelperTest < ActiveSupport::TestCase assert_equal "#{environment.currency_unit}13#{environment.currency_separator}70", float_to_currency_cart(value,environment) end - should 'return a table of items' do - enterprise = Enterprise.new(name: "Test Enterprise", identifier: "test-enterprise") - enterprise.environment = Environment.default - enterprise.save! - - product_category = fast_create(ProductCategory, :name => 'Products') - product = fast_create(Product, :name => 'test product1', :product_category_id => product_category.id, :profile_id => enterprise.id) - setting = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) - setting.delivery = true - setting.save! - - assert_match 'table id="cart-items-table"', items_table([product], enterprise) - assert_match 'test product1', items_table([product], enterprise) - 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 6383e5c..0a929a9 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb @@ -39,7 +39,7 @@
<%=s_('Your Order')%> <% supplier_delivery = @order.supplier_delivery || profile.delivery_methods.first %> - <%= items_table @cart[:items], @profile, supplier_delivery %> + <%= items_table @cart[:items], supplier_delivery %>
diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb index 30db225..9e60422 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb @@ -18,9 +18,11 @@
  • <%= c_('Email') %>: <%= @order.consumer_data[:email] %>
  • <%= _('Phone number') %>: <%= @order.consumer_data[:contact_phone] %>
  • -
  • <%= _("Payment's method") %>: <%= _ OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %>
  • - <% if @order.payment_data[:method] == 'money' %> -
  • <%= s_('shopping_cart|Change') %>: <%= @order.payment_data[:change] %>
  • + <% if @order.payment_data[:method] %> +
  • <%= _("Payment's method") %>: <%= _ OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %>
  • + <% if @order.payment_data[:method] == 'money' %> +
  • <%= s_('shopping_cart|Change') %>: <%= @order.payment_data[:change] %>
  • + <% end %> <% end %>
  • <%= _('Delivery or pickup') %>:
  • @@ -59,7 +61,7 @@

    <%=_('Here are the products you bought:')%>

    - <%= items_table(@items, @order.profile, @order.supplier_delivery, true) %> + <%= items_table(@items, @order.supplier_delivery, true) %>

    --
    <%=_('Thanks for buying with us!')%>
    diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb index 7771c50..3a63b78 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb @@ -16,9 +16,11 @@

  • <%= c_('Email') %>: <%= @order.consumer_data[:email] %>
  • <%= _('Phone number') %>: <%= @order.consumer_data[:contact_phone] %>
  • -
  • <%= _('Payment') %>: <%= OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %>
  • - <% if @order.payment_data[:method] == 'money' %> -
  • <%= s_('shopping_cart|Change') %>: <%= @order.payment_data[:change] %>
  • + <% if @order.payment_data[:method] %> +
  • <%= _('Payment') %>: <%= OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %>
  • + <% if @order.payment_data[:method] == 'money' %> +
  • <%= s_('shopping_cart|Change') %>: <%= @order.payment_data[:change] %>
  • + <% end %> <% end %> <% if !@order.consumer_delivery_data[:address].blank? || !@order.consumer_delivery_data[:city].blank? || !@order.consumer_delivery_data[:zip_code].blank? || !@order.consumer_delivery_data[:district].blank? || !@order.consumer_delivery_data[:address_reference].blank? %> @@ -51,7 +53,7 @@

    <%=_('And here are the items bought by this customer:')%>

    - <%= items_table(@items, @order.profile, @order.supplier_delivery, true) %> + <%= items_table(@items, @order.supplier_delivery, true) %>

    --
    <%=_('If there are any problems with this email contact the admin of %s.') % @environment.name %> diff --git a/test/fixtures/environments.yml b/test/fixtures/environments.yml index 757f297..afd9acd 100644 --- a/test/fixtures/environments.yml +++ b/test/fixtures/environments.yml @@ -3,6 +3,7 @@ colivre_net: id: 1 name: 'Colivre.net' contact_email: 'colivre@localhost.localdomain' + noreply_email: 'noreply@localhost.localdomain' is_default: true theme: 'noosfero' anhetegua_net: @@ -10,3 +11,4 @@ anhetegua_net: name: 'Anheteguá' is_default: false contact_email: 'anhetegua@localhost.localdomain' + noreply_email: 'noreply@localhost.localdomain' -- libgit2 0.21.2