diff --git a/lib/code_numbering.rb b/lib/code_numbering.rb new file mode 100644 index 0000000..843cc33 --- /dev/null +++ b/lib/code_numbering.rb @@ -0,0 +1,58 @@ +module CodeNumbering + module ClassMethods + def code_numbering field, options = {} + class_attribute :code_numbering_field + class_attribute :code_numbering_options + + self.code_numbering_field = field + self.code_numbering_options = options + + before_create :create_code_numbering + + include CodeNumbering::InstanceMethods + end + end + + module InstanceMethods + + def code + self.attributes[self.code_numbering_field.to_s] + end + + def code_scope + scope = self.code_numbering_options[:scope] + case scope + when Symbol + self.send scope + when Proc + instance_exec &scope + else + self.class + end + end + + def code_maximum + self.code_scope.maximum(self.code_numbering_field) || 0 + end + + def create_code_numbering + max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] + max = self.code_maximum + self.send "#{self.code_numbering_field}=", max+1 + end + + def reset_scope_code_numbering + max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] + max ||= 1 + + self.code_scope.order(:created_at).each do |record| + record.update_column self.code_numbering_field, max + max += 1 + end + self.reload + end + + end +end + +ActiveRecord::Base.extend CodeNumbering::ClassMethods diff --git a/lib/split_datetime.rb b/lib/split_datetime.rb new file mode 100644 index 0000000..be184bf --- /dev/null +++ b/lib/split_datetime.rb @@ -0,0 +1,72 @@ + +module SplitDatetime + + class << self + def nil_time + Time.parse "#{Time.now.hour}:0:0" + end + def nil_date + Date.today + end + + def to_time datetime + datetime = self.nil_time if datetime.blank? + datetime.to_formatted_s :time + end + def to_date datetime + datetime = self.nil_date if datetime.blank? + datetime.strftime '%d/%m/%Y' + end + def set_time datetime, value + value = if value.blank? + self.nil_time + elsif value.kind_of? String + Time.parse value + else + value.to_time + end + datetime = self.nil_date if datetime.blank? + + Time.mktime(datetime.year, datetime.month, datetime.day, value.hour, value.min, value.sec).to_datetime + end + def set_date datetime, value + value = if value.blank? + self.nil_date + elsif value.kind_of? String + DateTime.strptime value, '%d/%m/%Y' + else + value.to_time + end + datetime = nil_time if datetime.blank? + + Time.mktime(value.year, value.month, value.day, datetime.hour, datetime.min, datetime.sec).to_datetime + end + end + + module SplitMethods + + def split_datetime attr + define_method "#{attr}_time" do + datetime = send attr + SplitDatetime.to_time datetime + end + define_method "#{attr}_date" do + datetime = send attr + SplitDatetime.to_date datetime + end + define_method "#{attr}_time=" do |value| + datetime = send attr + send "#{attr}=", SplitDatetime.set_time(datetime, value) + end + define_method "#{attr}_date=" do |value| + datetime = send attr + send "#{attr}=", SplitDatetime.set_date(datetime, value) + end + end + + end + +end + +Class.extend SplitDatetime::SplitMethods +ActiveRecord::Base.extend SplitDatetime::SplitMethods diff --git a/plugins/delivery/features/delivery_admin.feature b/plugins/delivery/features/delivery_admin.feature deleted file mode 100644 index 9101a40..0000000 --- a/plugins/delivery/features/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/delivery/features/delivery_client.feature b/plugins/delivery/features/delivery_client.feature deleted file mode 100644 index 31fb8f0..0000000 --- a/plugins/delivery/features/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/delivery/features/step_definitions/delivery_steps.rb b/plugins/delivery/features/step_definitions/delivery_steps.rb deleted file mode 100644 index 93853ad..0000000 --- a/plugins/delivery/features/step_definitions/delivery_steps.rb +++ /dev/null @@ -1,14 +0,0 @@ -Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name| - status = status == 'enabled' - enterprise = Enterprise.find_by_name(name) || Enterprise[name] - settings = enterprise.shopping_cart_settings({:enabled => status}) - settings.save! -end - -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 diff --git a/plugins/fb_app/install.rb b/plugins/fb_app/install.rb index 158c8f0..fc6ed0b 100644 --- a/plugins/fb_app/install.rb +++ b/plugins/fb_app/install.rb @@ -1,3 +1,2 @@ -system "script/noosfero-plugins -q enable oauth_client" -system "script/noosfero-plugins -q enable open_graph" +system "script/noosfero-plugins -q enable oauth_client open_graph" diff --git a/plugins/orders/install.rb b/plugins/orders/install.rb new file mode 100644 index 0000000..156ab46 --- /dev/null +++ b/plugins/orders/install.rb @@ -0,0 +1,2 @@ +system "script/noosfero-plugins -q enable delivery" + diff --git a/plugins/orders/lib/code_numbering.rb b/plugins/orders/lib/code_numbering.rb deleted file mode 100644 index 843cc33..0000000 --- a/plugins/orders/lib/code_numbering.rb +++ /dev/null @@ -1,58 +0,0 @@ -module CodeNumbering - module ClassMethods - def code_numbering field, options = {} - class_attribute :code_numbering_field - class_attribute :code_numbering_options - - self.code_numbering_field = field - self.code_numbering_options = options - - before_create :create_code_numbering - - include CodeNumbering::InstanceMethods - end - end - - module InstanceMethods - - def code - self.attributes[self.code_numbering_field.to_s] - end - - def code_scope - scope = self.code_numbering_options[:scope] - case scope - when Symbol - self.send scope - when Proc - instance_exec &scope - else - self.class - end - end - - def code_maximum - self.code_scope.maximum(self.code_numbering_field) || 0 - end - - def create_code_numbering - max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] - max = self.code_maximum - self.send "#{self.code_numbering_field}=", max+1 - end - - def reset_scope_code_numbering - max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] - max ||= 1 - - self.code_scope.order(:created_at).each do |record| - record.update_column self.code_numbering_field, max - max += 1 - end - self.reload - end - - end -end - -ActiveRecord::Base.extend CodeNumbering::ClassMethods diff --git a/plugins/orders/plugin.yml b/plugins/orders/plugin.yml deleted file mode 100644 index 9f71450..0000000 --- a/plugins/orders/plugin.yml +++ /dev/null @@ -1,3 +0,0 @@ -name: orders -dependencies: - - delivery diff --git a/plugins/orders_cycle/install.rb b/plugins/orders_cycle/install.rb new file mode 100644 index 0000000..add1749 --- /dev/null +++ b/plugins/orders_cycle/install.rb @@ -0,0 +1,2 @@ +system "script/noosfero-plugins -q enable orders suppliers" + diff --git a/plugins/orders_cycle/plugin.yml b/plugins/orders_cycle/plugin.yml deleted file mode 100644 index 9f8461d..0000000 --- a/plugins/orders_cycle/plugin.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: orders_cycle -dependencies: - - orders - - suppliers - - volunteers diff --git a/plugins/orders_cycle/test/factories.rb b/plugins/orders_cycle/test/factories.rb deleted file mode 100644 index 021fdaf..0000000 --- a/plugins/orders_cycle/test/factories.rb +++ /dev/null @@ -1,57 +0,0 @@ -module OrdersCyclePlugin::Factory - - def defaults_for_suppliers_plugin_supplier - {:profile => build(Profile), - :consumer => build(Profile)} - end - - def defaults_for_suppliers_plugin_distributed_product attrs = {} - profile = attrs[:profile] || build(Profile) - {:profile => profile, :name => "product-#{factory_num_seq}", :price => 2.0, - :product => build(Product, :enterprise => profile.profile, :price => 2.0), - :supplier => build(SuppliersPlugin::Supplier, :profile => profile, :consumer => profile)} - end - - def defaults_for_orders_cycle_plugin_offered_product attrs = {} - hash = defaults_for_orders_cycle_plugin_product(attrs) - profile = hash[:profile] - hash.merge({ - :from_products => [build(SuppliersPlugin::DistributedProduct, :profile => profile)]}) - end - - def defaults_for_delivery_plugin_method - {:profile => build(OrdersCyclePlugin::Profile), - :name => "My delivery #{factory_num_seq.to_s}", - :delivery_type => 'deliver'} - end - - def defaults_for_delivery_plugin_option - {:cycle => build(OrdersCyclePlugin::Cycle), - :delivery_method => build(DeliveryPlugin::Method)} - end - - def defaults_for_orders_plugin_order attrs = {} - profile = attrs[:profile] || build(OrdersCyclePlugin::Profile) - {:status => 'ordered', - :cycle => build(OrdersCyclePlugin::Cycle, :profile => profile), - :consumer => build(OrdersCyclePlugin::Profile), - :supplier_delivery => build(DeliveryPlugin::Method, :profile => profile), - :consumer_delivery => build(DeliveryPlugin::Method, :profile => profile)} - end - - def defaults_for_orders_plugin_items - {:order => build(OrdersPlugin::Order), - :product => build(OrdersCyclePlugin::OfferedProduct), - :quantity_shipped => 1.0, :quantity_ordered => 2.0, :quantity_accepted => 3.0, - :price_shipped => 10.0, :price_ordered => 20.0, :price_accepted => 30.0} - end - - def defaults_for_orders_cycle_plugin_cycle - {:profile => build(OrdersCyclePlugin::Profile), :status => 'orders', - :name => 'weekly', :start => Time.now, :finish => Time.now+1.days} - end - -end - -Noosfero::Factory.register_extension OrdersCyclePlugin::Factory - diff --git a/plugins/orders_cycle/test/functional/orders_cycle_plugin/order_controller_test.rb b/plugins/orders_cycle/test/functional/orders_cycle_plugin/order_controller_test.rb deleted file mode 100644 index 9a93fce..0000000 --- a/plugins/orders_cycle/test/functional/orders_cycle_plugin/order_controller_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class OrdersCyclePlugin::OrderControllerTest < Test::Unit::TestCase - - def setup - @controller = OrdersCyclePluginOrderController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - - -end diff --git a/plugins/orders_cycle/test/functional/orders_cycle_plugin/session_controller_test.rb b/plugins/orders_cycle/test/functional/orders_cycle_plugin/session_controller_test.rb deleted file mode 100644 index 7ab2402..0000000 --- a/plugins/orders_cycle/test/functional/orders_cycle_plugin/session_controller_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class OrdersCyclePlugin::CycleControllerTest < Test::Unit::TestCase - - def setup - @controller = OrdersCyclePluginCycleController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - - should 'create a new cycle' do - end - -end diff --git a/plugins/orders_cycle/test/test_helper.rb b/plugins/orders_cycle/test/test_helper.rb deleted file mode 100644 index 3f0b088..0000000 --- a/plugins/orders_cycle/test/test_helper.rb +++ /dev/null @@ -1,6 +0,0 @@ -require File.dirname(__FILE__) + '/../../../test/test_helper' -require 'spec' - -class ActiveRecord::TestCase < ActiveSupport::TestCase - include OrdersCyclePluginFactory -end diff --git a/plugins/orders_cycle/test/unit/orders_cycle_plugin/cycle_test.rb b/plugins/orders_cycle/test/unit/orders_cycle_plugin/cycle_test.rb deleted file mode 100644 index 7c09b02..0000000 --- a/plugins/orders_cycle/test/unit/orders_cycle_plugin/cycle_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class OrdersCyclePlugin::CycleTest < ActiveSupport::TestCase - - def setup - @profile = Enterprise.create!(:name => "trocas verdes", :identifier => "trocas-verdes") - @pc = ProductCategory.create!(:name => 'frutas', :environment_id => 1) - @profile.products = [Product.create!(:name => 'banana', :product_category => @pc), - Product.new(:name => 'mandioca', :product_category => @pc), Product.new(:name => 'alface', :product_category => @pc)] - - profile.offered_products = @profile.products.map{ |p| OrdersCyclePlugin::OfferedProduct.create!(:product => p) } - DeliveryPlugin::Method.create! :name => 'at home', :delivery_type => 'pickup', :profile => @profile - @cycle = OrdersCyclePlugin::Cycle.create!(:profile => @profile) - end - - should 'add products from profile after create' do - assert_equal @cycle.products.collect(&:product_id), @profile.products.collect(&:id) - end - - should 'have at least one delivery method unless in edition status' do - cycle = OrdersCyclePlugin::Cycle.create! :profile => @profile, :name => "Testes batidos", :start => DateTime.now, :status => 'edition' - assert cycle - cycle.status = 'orders' - assert_nil cycle.save! - end - -end diff --git a/plugins/orders_cycle/test/unit/orders_cycle_plugin/offered_product_test.rb b/plugins/orders_cycle/test/unit/orders_cycle_plugin/offered_product_test.rb deleted file mode 100644 index 7a92fde..0000000 --- a/plugins/orders_cycle/test/unit/orders_cycle_plugin/offered_product_test.rb +++ /dev/null @@ -1,6 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class OrdersCyclePlugin::OfferedProductTest < ActiveSupport::TestCase - - -end diff --git a/plugins/orders_cycle/test/unit/profile_test.rb b/plugins/orders_cycle/test/unit/profile_test.rb deleted file mode 100644 index 4b2e21f..0000000 --- a/plugins/orders_cycle/test/unit/profile_test.rb +++ /dev/null @@ -1,127 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class OrdersCyclePlugin::ProfileTest < ActiveRecord::TestCase - - def setup - @profile = build(Profile) - @invisible_profile = build(Enterprise, :visible => false) - @other_profile = build(Enterprise) - @profile = build(OrdersCyclePlugin::profile, :profile => @profile) - @self_supplier = build(OrdersCyclePlugin::Supplier, :consumer => @profile, :profile => @profile) - @dummy_supplier = build(OrdersCyclePlugin::Supplier, :consumer => @profile, :profile => @dummy_profile) - @other_supplier = build(OrdersCyclePlugin::Supplier, :consumer => @profile, :profile => @other_profile) - end - - attr_accessor :profile, :invisible_profile, :other_profile, - :self_supplier, :dummy_supplier, :other_supplier - - should 'respond to name methods' do - profile.expects(:name).returns('name') - assert_equal 'name', profile.name - end - - should 'respond to dummy methods' do - profile.dummy = true - assert_equal true, profile.dummy? - profile.dummy = false - assert_equal false, profile.dummy - end - - should "return closed cycles' date range" do - DateTime.expects(:now).returns(1).at_least_once - assert_equal 1..1, profile.orders_cycles_closed_date_range - s1 = create(OrdersCyclePlugin::Cycle, :profile => profile, :start => Time.now-1.days, :finish => nil) - s2 = create(OrdersCyclePlugin::Cycle, :profile => profile, :finish => Time.now+1.days, :start => Time.now) - assert_equal (s1.start.to_date..s2.finish.to_date), profile.orders_cycles_closed_date_range - end - - should 'return abbreviation or the name' do - profile.name_abbreviation = 'coll.' - profile.profile.name = 'collective' - assert_equal 'coll.', profile.abbreviation_or_name - profile.name_abbreviation = nil - assert_equal 'collective', profile.abbreviation_or_name - end - - ### - # Products - ### - - should "default products's margins when asked" do - profile.update_attributes! :margin_percentage => 10 - product = create(SuppliersPlugin::DistributedProduct, :profile => profile, :supplier => profile.self_supplier, - :price => 10, :default_margin_percentage => false) - cycle = create(OrdersCyclePlugin::Cycle, :profile => profile) - sproduct = cycle.products.first - sproduct.update_attributes! :margin_percentage => 5 - cycleclosed = create(OrdersCyclePlugin::Cycle, :profile => profile, :status => 'closed') - - profile.orders_cycles_products_default_margins - product.reload - sproduct.reload - assert_equal true, product.default_margin_percentage - assert_equal sproduct.margin_percentage, profile.margin_percentage - end - - should 'return not yet distributed products' do - profile.save! - other_profile.save! - other_supplier.save! - product = create(SuppliersPlugin::DistributedProduct, :profile => other_profile, :supplier => other_profile.self_supplier) - profile.add_supplier_products other_supplier - product2 = create(SuppliersPlugin::DistributedProduct, :profile => other_profile, :supplier => other_profile.self_supplier) - assert_equal [product2], profile.not_distributed_products(other_supplier) - end - - ### - # Suppliers - ### - - should 'add supplier' do - @profile.save! - @other_profile.save! - - assert_difference OrdersCyclePlugin::Supplier, :count do - @profile.add_supplier @other_profile - end - assert @profile.suppliers_profiles.include?(@other_profile) - assert @other_profile.consumers_profiles.include?(@profile) - end - - should "add all supplier's products when supplier is added" do - @profile.save! - @other_profile.save! - product = create(SuppliersPlugin::DistributedProduct, :profile => @other_profile) - @profile.add_supplier @other_profile - assert_equal [product], @profile.from_products - end - - should 'remove supplier' do - @profile.save! - @other_profile.save! - - @profile.add_supplier @other_profile - assert_difference OrdersCyclePlugin::Supplier, :count, -1 do - assert_difference RoleAssignment, :count, -1 do - @profile.remove_supplier @other_profile - end - end - assert !@profile.suppliers_profiles.include?(@other_profile) - end - - should "archive supplier's products when supplier is removed" do - @profile.save! - @other_profile.save! - product = create(SuppliersPlugin::DistributedProduct, :profile => @other_profile) - @profile.add_supplier @other_profile - @profile.remove_supplier @other_profile - assert_equal [product], @profile.from_products - assert_equal 1, @profile.distributed_products.archived.count - end - - should 'create self supplier automatically' do - profile = create(OrdersCyclePlugin::profile, :profile => @profile) - assert_equal 1, profile.suppliers.count - end - -end diff --git a/plugins/shopping_cart/delivery_admin.feature b/plugins/shopping_cart/delivery_admin.feature new file mode 100644 index 0000000..9101a40 --- /dev/null +++ b/plugins/shopping_cart/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/delivery_client.feature b/plugins/shopping_cart/delivery_client.feature new file mode 100644 index 0000000..31fb8f0 --- /dev/null +++ b/plugins/shopping_cart/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/install.rb b/plugins/shopping_cart/install.rb new file mode 100644 index 0000000..609d603 --- /dev/null +++ b/plugins/shopping_cart/install.rb @@ -0,0 +1,2 @@ +system "script/noosfero-plugins -q enable orders delivery" + diff --git a/plugins/shopping_cart/plugin.yml b/plugins/shopping_cart/plugin.yml deleted file mode 100644 index 33ee6d0..0000000 --- a/plugins/shopping_cart/plugin.yml +++ /dev/null @@ -1,3 +0,0 @@ -name: shopping_cart -dependencies: - - orders diff --git a/plugins/shopping_cart/step_definitions/delivery_steps.rb b/plugins/shopping_cart/step_definitions/delivery_steps.rb new file mode 100644 index 0000000..93853ad --- /dev/null +++ b/plugins/shopping_cart/step_definitions/delivery_steps.rb @@ -0,0 +1,14 @@ +Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name| + status = status == 'enabled' + enterprise = Enterprise.find_by_name(name) || Enterprise[name] + settings = enterprise.shopping_cart_settings({:enabled => status}) + settings.save! +end + +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 diff --git a/plugins/suppliers/test/test_helper.rb b/plugins/suppliers/test/test_helper.rb deleted file mode 100644 index cca1fd3..0000000 --- a/plugins/suppliers/test/test_helper.rb +++ /dev/null @@ -1 +0,0 @@ -require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/suppliers/test/unit/code_numbering_test.rb b/plugins/suppliers/test/unit/code_numbering_test.rb deleted file mode 100644 index 0fcb79a..0000000 --- a/plugins/suppliers/test/unit/code_numbering_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' - -class CodeNumberingTest < ActiveSupport::TestCase - - -end - diff --git a/plugins/suppliers/test/unit/default_delegate_test.rb b/plugins/suppliers/test/unit/default_delegate_test.rb deleted file mode 100644 index 525796d..0000000 --- a/plugins/suppliers/test/unit/default_delegate_test.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'test_helper' - -class DefaultDelegateTest < ActiveSupport::TestCase - - -end diff --git a/plugins/suppliers/test/unit/suppliers_plugin/distributed_product_test.rb b/plugins/suppliers/test/unit/suppliers_plugin/distributed_product_test.rb deleted file mode 100644 index ddcd396..0000000 --- a/plugins/suppliers/test/unit/suppliers_plugin/distributed_product_test.rb +++ /dev/null @@ -1,108 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class SuppliersPlugin::DistributedProductTest < ActiveSupport::TestCase - - def setup - @product_category = create(ProductCategory, :name => 'parent') - @profile = build(Enterprise) - @invisible_profile = build(Enterprise, :visible => false) - @other_profile = build(Enterprise) - @self_supplier = build(SuppliersPlugin::Supplier, :consumer => @profile, :profile => @profile) - @dummy_supplier = build(SuppliersPlugin::Supplier, :consumer => @profile, :profile => @dummy_profile) - @other_supplier = build(SuppliersPlugin::Supplier, :consumer => @profile, :profile => @other_profile) - end - - attr_accessor :product_category, - :profile, :invisible_profile, :other_profile, - :profile, :dummy_profile, :other_profile, :self_supplier, :dummy_supplier, :other_supplier - - should 'return default settings considering dummy supplier' do - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @dummy_supplier) - assert_equal nil, product.default_name - assert_equal nil, product.default_description - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @other_supplier) - assert_equal true, product.default_name - assert_equal true, product.default_description - end - - should 'return price without margins if it is own product' do - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @profile, :supplier => @self_supplier) - assert_equal 10.0, product.price.to_f - end - - should 'return price without margins if supplier product has no price' do - supplier_product = build(SuppliersPlugin::DistributedProduct, :profile => @other_profile, :supplier => @other_profile.self_supplier) - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @profile, :supplier => @other_supplier) - assert_equal 10.0, product.price.to_f - end - - should 'return price with margins' do - supplier_product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @other_profile, :supplier => @other_profile.self_supplier) - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :supplier_product => supplier_product, :profile => @profile, :supplier => @other_supplier) - - product.default_margin_percentage = false - assert_equal 11.0, product.price.to_f - profile.margin_percentage = 20 - product.default_margin_percentage = true - assert_equal 12.0, product.price.to_f - end - - should 'allow set of supplier product' do - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @profile, :supplier => @self_supplier) - - product.from_product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @self_supplier) - assert_nothing_raised do - product.supplier_product = {:price => 10, :margin_percentage => 10} - product.supplier_product = SuppliersPlugin::DistributedProduct.new :price => 5 - end - end - - should 'create a supplier product for a dummy supplier' do - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @dummy_supplier) - assert product.supplier_product - # negative assertion - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @other_supplier) - assert !product.supplier_product - end - - should 'respond to supplier_product_id setter and getter' do - product = create(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @dummy_supplier) - assert_equal product.supplier_product.id, product.supplier_product_id - product.expects(:distribute_from) - product.supplier_product_id = 1 - end - - should 'respond to distribute_from' do - product = create(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @profile.self_supplier) - - assert_raise RuntimeError do - supplier_product = build(SuppliersPlugin::DistributedProduct, :profile => @other_profile) - product.distribute_from(supplier_product) - end - - supplier_product = create(SuppliersPlugin::DistributedProduct, :profile => @other_profile) - product.profile.add_supplier @other_profile - product.distribute_from supplier_product - assert_equal product.supplier.profile, supplier_product.profile - assert_equal product.supplier.profile, supplier_product.profile - end - - should 'return json for category hierarchy' do - grandparent = create(ProductCategory, :name => 'grand parent') - parent = create(ProductCategory, :name => 'parent') - child = product_category - - product = SuppliersPlugin::DistributedProduct.new :category => parent - hash = {:own_name => "parent", :id => "2", :subcats => [], :name => "parent", - :hierarchy => [{:own_name => "parent", :subcats => [], :name => "parent", :id => "2"}]} - assert_equal hash, product.json_for_category - end - - should 'block own product distribution' do - product = Product.create :enterprise => @profile, :product_category => product_category - distributed = SuppliersPlugin::DistributedProduct.new :enterprise => @profile, :from_products => [product] - - assert distributed.invalid? - end - -end diff --git a/plugins/suppliers/test/unit/suppliers_plugin/product_test.rb b/plugins/suppliers/test/unit/suppliers_plugin/product_test.rb deleted file mode 100644 index 947ba74..0000000 --- a/plugins/suppliers/test/unit/suppliers_plugin/product_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require "test_helper" - -class SuppliersPlugin::ProductTest < ActiveSupport::TestCase - - def setup - @product = build(SuppliersPlugin::BaseProduct) - end - - should 'return first from product as supplier product' do - fp = build(SuppliersPlugin::BaseProduct, :profile => @product.profile) - @product.from_products = [fp] - assert_equal fp, @product.from_product - assert_equal fp, @product.supplier_product - end - - should 'respond to dummy and own' do - assert !@product.dummy? - assert @product.own? - end - - should 'return price with margins' do - supplier_product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @product.profile, :supplier => @product.profile.self_supplier) - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :supplier_product => supplier_product, :profile => @product.profile, :supplier => @product.profile.self_supplier) - - product.default_margin_percentage = false - assert_equal 11.0, product.price_with_margins - @product.profile.margin_percentage = 20 - product.default_margin_percentage = true - assert_equal 12.0, product.price_with_margins - end - - should 'build default unit if none exists' do - assert_equal 0, Unit.count - assert 'unit', @product.unit.singular - end - - should 'avoid destroy by raising an exception' do - assert_raise RuntimeError do - @product.destroy - end - end - - should 'accept price in different formats' do - @product.price = '2,45' - assert_equal 2.45, @product.price - end - - -end diff --git a/plugins/suppliers/test/unit/suppliers_plugin/source_product_test.rb b/plugins/suppliers/test/unit/suppliers_plugin/source_product_test.rb deleted file mode 100644 index a043536..0000000 --- a/plugins/suppliers/test/unit/suppliers_plugin/source_product_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class SuppliersPlugin::SourceProductTest < ActiveSupport::TestCase - - def setup - end - -end diff --git a/plugins/suppliers/test/unit/suppliers_plugin/supplier_test.rb b/plugins/suppliers/test/unit/suppliers_plugin/supplier_test.rb deleted file mode 100644 index f3d53c9..0000000 --- a/plugins/suppliers/test/unit/suppliers_plugin/supplier_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class SuppliersPlugin::SupplierTest < ActiveSupport::TestCase - - def setup - end - -end diff --git a/plugins/volunteers/lib/split_datetime.rb b/plugins/volunteers/lib/split_datetime.rb deleted file mode 100644 index be184bf..0000000 --- a/plugins/volunteers/lib/split_datetime.rb +++ /dev/null @@ -1,72 +0,0 @@ - -module SplitDatetime - - class << self - def nil_time - Time.parse "#{Time.now.hour}:0:0" - end - def nil_date - Date.today - end - - def to_time datetime - datetime = self.nil_time if datetime.blank? - datetime.to_formatted_s :time - end - def to_date datetime - datetime = self.nil_date if datetime.blank? - datetime.strftime '%d/%m/%Y' - end - def set_time datetime, value - value = if value.blank? - self.nil_time - elsif value.kind_of? String - Time.parse value - else - value.to_time - end - datetime = self.nil_date if datetime.blank? - - Time.mktime(datetime.year, datetime.month, datetime.day, value.hour, value.min, value.sec).to_datetime - end - def set_date datetime, value - value = if value.blank? - self.nil_date - elsif value.kind_of? String - DateTime.strptime value, '%d/%m/%Y' - else - value.to_time - end - datetime = nil_time if datetime.blank? - - Time.mktime(value.year, value.month, value.day, datetime.hour, datetime.min, datetime.sec).to_datetime - end - end - - module SplitMethods - - def split_datetime attr - define_method "#{attr}_time" do - datetime = send attr - SplitDatetime.to_time datetime - end - define_method "#{attr}_date" do - datetime = send attr - SplitDatetime.to_date datetime - end - define_method "#{attr}_time=" do |value| - datetime = send attr - send "#{attr}=", SplitDatetime.set_time(datetime, value) - end - define_method "#{attr}_date=" do |value| - datetime = send attr - send "#{attr}=", SplitDatetime.set_date(datetime, value) - end - end - - end - -end - -Class.extend SplitDatetime::SplitMethods -ActiveRecord::Base.extend SplitDatetime::SplitMethods diff --git a/plugins/volunteers/test/unit/split_datetime_test.rb b/plugins/volunteers/test/unit/split_datetime_test.rb deleted file mode 100644 index 9bdeaec..0000000 --- a/plugins/volunteers/test/unit/split_datetime_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' - -class ModelWithDate - - def initialize - @delivery = DateTime.now - end - - attr_accessor :delivery - - extend SplitDatetime::SplitMethods - split_datetime :delivery - -end - -class SplitDatetimeTest < ActiveSupport::TestCase - - def setup - @m = ModelWithDate.new - @m.delivery = (Time.mktime(2011) + 2.hours + 2.minutes + 2.seconds).to_datetime - end - - should 'return get splitted times' do - assert_equal @m.delivery_date, '2011-01-01' - assert_equal @m.delivery_time, '02:02' - end - - should 'return set splitted times by Date' do - @m.delivery_date = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime - assert_equal @m.delivery_date, '2011-03-05' - assert_equal @m.delivery_time, '02:02' - end - - should 'return set splitted times by Time' do - @m.delivery_time = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime - assert_equal @m.delivery_date, '2011-01-01' - assert_equal @m.delivery_time, '03:03' - end - - should 'return set splitted times by Date String' do - @m.delivery_date = "2011-11-11" - assert_equal @m.delivery_date, '2011-11-11' - assert_equal @m.delivery_time, '02:02' - end - - should 'return set splitted times by Time String' do - @m.delivery_time = "15:43" - assert_equal @m.delivery_date, '2011-01-01' - assert_equal @m.delivery_time, '15:43' - end - -end - diff --git a/test/unit/split_datetime_test.rb b/test/unit/split_datetime_test.rb new file mode 100644 index 0000000..f469398 --- /dev/null +++ b/test/unit/split_datetime_test.rb @@ -0,0 +1,53 @@ +require 'test_helper' + +class ModelWithDate + + def initialize + @delivery = DateTime.now + end + + attr_accessor :delivery + + extend SplitDatetime::SplitMethods + split_datetime :delivery + +end + +class SplitDatetimeTest < ActiveSupport::TestCase + + def setup + @m = ModelWithDate.new + @m.delivery = (Time.mktime(2011) + 2.hours + 2.minutes + 2.seconds).to_datetime + end + + should 'return get splitted times' do + assert_equal '01/01/2011', @m.delivery_date + assert_equal '02:02', @m.delivery_time + end + + should 'return set splitted times by Date' do + @m.delivery_date = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime + assert_equal '05/03/2011', @m.delivery_date + assert_equal '02:02', @m.delivery_time + end + + should 'return set splitted times by Time' do + @m.delivery_time = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime + assert_equal '01/01/2011', @m.delivery_date + assert_equal '03:03', @m.delivery_time + end + + should 'return set splitted times by Date String' do + @m.delivery_date = "11/11/2011" + assert_equal '11/11/2011', @m.delivery_date + assert_equal '02:02', @m.delivery_time + end + + should 'return set splitted times by Time String' do + @m.delivery_time = "15:43" + assert_equal '01/01/2011', @m.delivery_date + assert_equal '15:43', @m.delivery_time + end + +end + -- libgit2 0.21.2