Commit 255387618964b6796594fdaf43158605cd573356

Authored by Braulio Bhavamitra
1 parent c99dd6da

Fix tests and plugins dependencies

Showing 33 changed files with 362 additions and 804 deletions   Show diff stats
lib/code_numbering.rb 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +module CodeNumbering
  2 + module ClassMethods
  3 + def code_numbering field, options = {}
  4 + class_attribute :code_numbering_field
  5 + class_attribute :code_numbering_options
  6 +
  7 + self.code_numbering_field = field
  8 + self.code_numbering_options = options
  9 +
  10 + before_create :create_code_numbering
  11 +
  12 + include CodeNumbering::InstanceMethods
  13 + end
  14 + end
  15 +
  16 + module InstanceMethods
  17 +
  18 + def code
  19 + self.attributes[self.code_numbering_field.to_s]
  20 + end
  21 +
  22 + def code_scope
  23 + scope = self.code_numbering_options[:scope]
  24 + case scope
  25 + when Symbol
  26 + self.send scope
  27 + when Proc
  28 + instance_exec &scope
  29 + else
  30 + self.class
  31 + end
  32 + end
  33 +
  34 + def code_maximum
  35 + self.code_scope.maximum(self.code_numbering_field) || 0
  36 + end
  37 +
  38 + def create_code_numbering
  39 + max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start]
  40 + max = self.code_maximum
  41 + self.send "#{self.code_numbering_field}=", max+1
  42 + end
  43 +
  44 + def reset_scope_code_numbering
  45 + max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start]
  46 + max ||= 1
  47 +
  48 + self.code_scope.order(:created_at).each do |record|
  49 + record.update_column self.code_numbering_field, max
  50 + max += 1
  51 + end
  52 + self.reload
  53 + end
  54 +
  55 + end
  56 +end
  57 +
  58 +ActiveRecord::Base.extend CodeNumbering::ClassMethods
... ...
lib/split_datetime.rb 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +
  2 +module SplitDatetime
  3 +
  4 + class << self
  5 + def nil_time
  6 + Time.parse "#{Time.now.hour}:0:0"
  7 + end
  8 + def nil_date
  9 + Date.today
  10 + end
  11 +
  12 + def to_time datetime
  13 + datetime = self.nil_time if datetime.blank?
  14 + datetime.to_formatted_s :time
  15 + end
  16 + def to_date datetime
  17 + datetime = self.nil_date if datetime.blank?
  18 + datetime.strftime '%d/%m/%Y'
  19 + end
  20 + def set_time datetime, value
  21 + value = if value.blank?
  22 + self.nil_time
  23 + elsif value.kind_of? String
  24 + Time.parse value
  25 + else
  26 + value.to_time
  27 + end
  28 + datetime = self.nil_date if datetime.blank?
  29 +
  30 + Time.mktime(datetime.year, datetime.month, datetime.day, value.hour, value.min, value.sec).to_datetime
  31 + end
  32 + def set_date datetime, value
  33 + value = if value.blank?
  34 + self.nil_date
  35 + elsif value.kind_of? String
  36 + DateTime.strptime value, '%d/%m/%Y'
  37 + else
  38 + value.to_time
  39 + end
  40 + datetime = nil_time if datetime.blank?
  41 +
  42 + Time.mktime(value.year, value.month, value.day, datetime.hour, datetime.min, datetime.sec).to_datetime
  43 + end
  44 + end
  45 +
  46 + module SplitMethods
  47 +
  48 + def split_datetime attr
  49 + define_method "#{attr}_time" do
  50 + datetime = send attr
  51 + SplitDatetime.to_time datetime
  52 + end
  53 + define_method "#{attr}_date" do
  54 + datetime = send attr
  55 + SplitDatetime.to_date datetime
  56 + end
  57 + define_method "#{attr}_time=" do |value|
  58 + datetime = send attr
  59 + send "#{attr}=", SplitDatetime.set_time(datetime, value)
  60 + end
  61 + define_method "#{attr}_date=" do |value|
  62 + datetime = send attr
  63 + send "#{attr}=", SplitDatetime.set_date(datetime, value)
  64 + end
  65 + end
  66 +
  67 + end
  68 +
  69 +end
  70 +
  71 +Class.extend SplitDatetime::SplitMethods
  72 +ActiveRecord::Base.extend SplitDatetime::SplitMethods
... ...
plugins/delivery/features/delivery_admin.feature
... ... @@ -1,81 +0,0 @@
1   -Feature: delivery administration
2   - As an enterprise's administrator
3   - I want to create delivery methods
4   - In order to allow my customer to choose which delivery they want
5   -
6   - Background:
7   - Given "ShoppingCart" plugin is enabled
8   - And "Delivery" plugin is enabled
9   - And the following users
10   - | login | name |
11   - | moe | Moe |
12   - And the following enterprise
13   - | identifier | name | owner |
14   - | moes-tavern | Moes Tavern | moe |
15   - And the shopping basket is enabled on "Moes Tavern"
16   - And "Moe" is admin of "Moes Tavern"
17   - And I am logged in as "moe"
18   - And I go to moes-tavern's control panel
19   -
20   - @selenium
21   - Scenario: enable delivery
22   - Given I follow "Shopping basket"
23   - When I check "Enable shopping basket"
24   - Then I should see "Deliveries or pickups"
25   -
26   - @selenium
27   - Scenario: disable delivery
28   - Given I follow "Shopping basket"
29   - When I uncheck "Enable shopping basket"
30   - Then I should not see "Deliveries or pickups"
31   -
32   - @selenium
33   - Scenario: create new deliver
34   - Given I follow "Shopping basket"
35   - And I check "Enable shopping basket"
36   - And I follow "New delivery or pickup"
37   - And I select "Deliver" from "Type"
38   - And I fill in "Name" with "Bike"
39   - And I fill in "Description" with "Beers delivered with my old bike."
40   - And I fill in "Fixed cost" with "8.00"
41   - And I fill in "Order's minimum price for free delivery" with "35.50"
42   - When I press "Add"
43   - Then I should see "Bike" within ".delivery-method"
44   -
45   - @selenium
46   - Scenario: create new pickup
47   - Given I follow "Shopping basket"
48   - And I check "Enable shopping basket"
49   - And I follow "New delivery or pickup"
50   - And I select "Pickup" from "Type"
51   - And I fill in "Name" with "Bar"
52   - And I fill in "Description" with "Come to my bar and pick it yourself."
53   - And I fill in "Fixed cost" with "0.00"
54   - When I press "Add"
55   - Then I should see "Bar"
56   -
57   - @selenium
58   - Scenario: remove delivery
59   - Given I follow "Shopping basket"
60   - And I check "Enable shopping basket"
61   - And I follow "New delivery or pickup"
62   - And I fill in "Name" with "Bike"
63   - When I press "Add"
64   - Then I should see "Bike"
65   - And I follow "Remove" within ".delivery-method"
66   - When I confirm the browser dialog
67   - Then I should see "Bike"
68   -
69   - @selenium
70   - Scenario: edit delivery
71   - Given I follow "Shopping basket"
72   - And I check "Enable shopping basket"
73   - And I follow "New delivery or pickup"
74   - And I fill in "Name" with "Bike"
75   - When I press "Add"
76   - Then I should see "Bike"
77   - And I follow "Edit" within ".delivery-method"
78   - And I fill in "Name" with "Car"
79   - When I press "Save"
80   - Then I should not see "Bike"
81   - Then I should see "Car"
plugins/delivery/features/delivery_client.feature
... ... @@ -1,77 +0,0 @@
1   -Feature: delivery client
2   - As an enterprise's client
3   - I want to choose the delivery method
4   - In order to receive my procucts properly
5   -
6   - Background:
7   - Given "ShoppingCart" plugin is enabled
8   - And "Delivery" plugin is enabled
9   - And the following users
10   - | login | name | email |
11   - | moe | Moe | moe@springfield.com |
12   - | homer | Homer | homer@springfield.com |
13   - And the following enterprise
14   - | identifier | name | owner |
15   - | moes-tavern | Moes Tavern | moe |
16   - And the shopping basket is enabled on "Moes Tavern"
17   - And the following product_categories
18   - | name |
19   - | Beer |
20   - | Snacks |
21   - And the following products
22   - | owner | category | name | price |
23   - | moes-tavern | beer | Duff | 3.00 |
24   - | moes-tavern | snacks | French fries | 7.00 |
25   - And "moes-tavern" has the following delivery methods
26   - | delivery_type | name | description | fixed_cost | free_over_price |
27   - | deliver | Bike | My good old bike. | 8.00 | 10.00 |
28   - | pickup | Bar | Come to my bar and drink it! | 0.00 | 0.00 |
29   - And feature "products_for_enterprises" is enabled on environment
30   - And I am logged in as "homer"
31   - And I go to moes-tavern's products page
32   -
33   - @selenium
34   - Scenario: choose deliver method for purchase
35   - Given I follow "Add to basket"
36   - And I follow "Add to basket"
37   - And I should see "Show basket"
38   - And I follow "Show basket"
39   - And I follow "Shopping checkout"
40   - And I fill in "Contact phone" with "123456789"
41   - When I select "Bike ($8.00)" from "Option"
42   - Then I should see "My good old bike." within ".instructions"
43   - And I should see "Address"
44   - And I should see "Bike" within "#delivery-name"
45   - And I should see "8.00" within "#delivery-price"
46   -
47   - @selenium
48   - Scenario: choose pickup method for purchase
49   - Given I follow "Add to basket"
50   - And I follow "Add to basket"
51   - And I should see "Show basket"
52   - And I follow "Show basket"
53   - And I follow "Shopping checkout"
54   - And I fill in "Contact phone" with "123456789"
55   - When I select "Bar" from "Option"
56   - Then I should see "Come to my bar and drink it!" within ".instructions"
57   - And I should not see "Address"
58   - And I should see "Bar" within "#delivery-name"
59   - And I should see "0.00" within "#delivery-price"
60   -
61   - @selenium
62   - Scenario: gets free delivery due to free over price
63   - Given I follow "Add to basket"
64   - And I follow "Add to basket"
65   - And I follow "Add to basket"
66   - And I follow "Add to basket"
67   - And I follow "Add to basket"
68   - And I follow "Add to basket"
69   - And I should see "Show basket"
70   - And I follow "Show basket"
71   - And I follow "Shopping checkout"
72   - And I fill in "Contact phone" with "123456789"
73   - When I select "Bike ($8.00)" from "Option"
74   - Then I should see "My good old bike." within ".instructions"
75   - And I should see "Address"
76   - And I should see "Bike" within "#delivery-name"
77   - And I should see "0.00" within "#delivery-price"
plugins/delivery/features/step_definitions/delivery_steps.rb
... ... @@ -1,14 +0,0 @@
1   -Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name|
2   - status = status == 'enabled'
3   - enterprise = Enterprise.find_by_name(name) || Enterprise[name]
4   - settings = enterprise.shopping_cart_settings({:enabled => status})
5   - settings.save!
6   -end
7   -
8   -Given /^"([^""]*)" has the following delivery methods$/ do |name, table|
9   - enterprise = Enterprise.find_by_name(name) || Enterprise[name]
10   - table.hashes.map{|item| item.dup}.each do |item|
11   - delivery_method = enterprise.delivery_methods.build
12   - delivery_method.update_attributes(item)
13   - end
14   -end
plugins/fb_app/install.rb
1   -system "script/noosfero-plugins -q enable oauth_client"
2   -system "script/noosfero-plugins -q enable open_graph"
  1 +system "script/noosfero-plugins -q enable oauth_client open_graph"
3 2  
... ...
plugins/orders/install.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +system "script/noosfero-plugins -q enable delivery"
  2 +
... ...
plugins/orders/lib/code_numbering.rb
... ... @@ -1,58 +0,0 @@
1   -module CodeNumbering
2   - module ClassMethods
3   - def code_numbering field, options = {}
4   - class_attribute :code_numbering_field
5   - class_attribute :code_numbering_options
6   -
7   - self.code_numbering_field = field
8   - self.code_numbering_options = options
9   -
10   - before_create :create_code_numbering
11   -
12   - include CodeNumbering::InstanceMethods
13   - end
14   - end
15   -
16   - module InstanceMethods
17   -
18   - def code
19   - self.attributes[self.code_numbering_field.to_s]
20   - end
21   -
22   - def code_scope
23   - scope = self.code_numbering_options[:scope]
24   - case scope
25   - when Symbol
26   - self.send scope
27   - when Proc
28   - instance_exec &scope
29   - else
30   - self.class
31   - end
32   - end
33   -
34   - def code_maximum
35   - self.code_scope.maximum(self.code_numbering_field) || 0
36   - end
37   -
38   - def create_code_numbering
39   - max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start]
40   - max = self.code_maximum
41   - self.send "#{self.code_numbering_field}=", max+1
42   - end
43   -
44   - def reset_scope_code_numbering
45   - max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start]
46   - max ||= 1
47   -
48   - self.code_scope.order(:created_at).each do |record|
49   - record.update_column self.code_numbering_field, max
50   - max += 1
51   - end
52   - self.reload
53   - end
54   -
55   - end
56   -end
57   -
58   -ActiveRecord::Base.extend CodeNumbering::ClassMethods
plugins/orders/plugin.yml
... ... @@ -1,3 +0,0 @@
1   -name: orders
2   -dependencies:
3   - - delivery
plugins/orders_cycle/install.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +system "script/noosfero-plugins -q enable orders suppliers"
  2 +
... ...
plugins/orders_cycle/plugin.yml
... ... @@ -1,5 +0,0 @@
1   -name: orders_cycle
2   -dependencies:
3   - - orders
4   - - suppliers
5   - - volunteers
plugins/orders_cycle/test/factories.rb
... ... @@ -1,57 +0,0 @@
1   -module OrdersCyclePlugin::Factory
2   -
3   - def defaults_for_suppliers_plugin_supplier
4   - {:profile => build(Profile),
5   - :consumer => build(Profile)}
6   - end
7   -
8   - def defaults_for_suppliers_plugin_distributed_product attrs = {}
9   - profile = attrs[:profile] || build(Profile)
10   - {:profile => profile, :name => "product-#{factory_num_seq}", :price => 2.0,
11   - :product => build(Product, :enterprise => profile.profile, :price => 2.0),
12   - :supplier => build(SuppliersPlugin::Supplier, :profile => profile, :consumer => profile)}
13   - end
14   -
15   - def defaults_for_orders_cycle_plugin_offered_product attrs = {}
16   - hash = defaults_for_orders_cycle_plugin_product(attrs)
17   - profile = hash[:profile]
18   - hash.merge({
19   - :from_products => [build(SuppliersPlugin::DistributedProduct, :profile => profile)]})
20   - end
21   -
22   - def defaults_for_delivery_plugin_method
23   - {:profile => build(OrdersCyclePlugin::Profile),
24   - :name => "My delivery #{factory_num_seq.to_s}",
25   - :delivery_type => 'deliver'}
26   - end
27   -
28   - def defaults_for_delivery_plugin_option
29   - {:cycle => build(OrdersCyclePlugin::Cycle),
30   - :delivery_method => build(DeliveryPlugin::Method)}
31   - end
32   -
33   - def defaults_for_orders_plugin_order attrs = {}
34   - profile = attrs[:profile] || build(OrdersCyclePlugin::Profile)
35   - {:status => 'ordered',
36   - :cycle => build(OrdersCyclePlugin::Cycle, :profile => profile),
37   - :consumer => build(OrdersCyclePlugin::Profile),
38   - :supplier_delivery => build(DeliveryPlugin::Method, :profile => profile),
39   - :consumer_delivery => build(DeliveryPlugin::Method, :profile => profile)}
40   - end
41   -
42   - def defaults_for_orders_plugin_items
43   - {:order => build(OrdersPlugin::Order),
44   - :product => build(OrdersCyclePlugin::OfferedProduct),
45   - :quantity_shipped => 1.0, :quantity_ordered => 2.0, :quantity_accepted => 3.0,
46   - :price_shipped => 10.0, :price_ordered => 20.0, :price_accepted => 30.0}
47   - end
48   -
49   - def defaults_for_orders_cycle_plugin_cycle
50   - {:profile => build(OrdersCyclePlugin::Profile), :status => 'orders',
51   - :name => 'weekly', :start => Time.now, :finish => Time.now+1.days}
52   - end
53   -
54   -end
55   -
56   -Noosfero::Factory.register_extension OrdersCyclePlugin::Factory
57   -
plugins/orders_cycle/test/functional/orders_cycle_plugin/order_controller_test.rb
... ... @@ -1,12 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class OrdersCyclePlugin::OrderControllerTest < Test::Unit::TestCase
4   -
5   - def setup
6   - @controller = OrdersCyclePluginOrderController.new
7   - @request = ActionController::TestRequest.new
8   - @response = ActionController::TestResponse.new
9   - end
10   -
11   -
12   -end
plugins/orders_cycle/test/functional/orders_cycle_plugin/session_controller_test.rb
... ... @@ -1,14 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class OrdersCyclePlugin::CycleControllerTest < Test::Unit::TestCase
4   -
5   - def setup
6   - @controller = OrdersCyclePluginCycleController.new
7   - @request = ActionController::TestRequest.new
8   - @response = ActionController::TestResponse.new
9   - end
10   -
11   - should 'create a new cycle' do
12   - end
13   -
14   -end
plugins/orders_cycle/test/test_helper.rb
... ... @@ -1,6 +0,0 @@
1   -require File.dirname(__FILE__) + '/../../../test/test_helper'
2   -require 'spec'
3   -
4   -class ActiveRecord::TestCase < ActiveSupport::TestCase
5   - include OrdersCyclePluginFactory
6   -end
plugins/orders_cycle/test/unit/orders_cycle_plugin/cycle_test.rb
... ... @@ -1,27 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class OrdersCyclePlugin::CycleTest < ActiveSupport::TestCase
4   -
5   - def setup
6   - @profile = Enterprise.create!(:name => "trocas verdes", :identifier => "trocas-verdes")
7   - @pc = ProductCategory.create!(:name => 'frutas', :environment_id => 1)
8   - @profile.products = [Product.create!(:name => 'banana', :product_category => @pc),
9   - Product.new(:name => 'mandioca', :product_category => @pc), Product.new(:name => 'alface', :product_category => @pc)]
10   -
11   - profile.offered_products = @profile.products.map{ |p| OrdersCyclePlugin::OfferedProduct.create!(:product => p) }
12   - DeliveryPlugin::Method.create! :name => 'at home', :delivery_type => 'pickup', :profile => @profile
13   - @cycle = OrdersCyclePlugin::Cycle.create!(:profile => @profile)
14   - end
15   -
16   - should 'add products from profile after create' do
17   - assert_equal @cycle.products.collect(&:product_id), @profile.products.collect(&:id)
18   - end
19   -
20   - should 'have at least one delivery method unless in edition status' do
21   - cycle = OrdersCyclePlugin::Cycle.create! :profile => @profile, :name => "Testes batidos", :start => DateTime.now, :status => 'edition'
22   - assert cycle
23   - cycle.status = 'orders'
24   - assert_nil cycle.save!
25   - end
26   -
27   -end
plugins/orders_cycle/test/unit/orders_cycle_plugin/offered_product_test.rb
... ... @@ -1,6 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class OrdersCyclePlugin::OfferedProductTest < ActiveSupport::TestCase
4   -
5   -
6   -end
plugins/orders_cycle/test/unit/profile_test.rb
... ... @@ -1,127 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class OrdersCyclePlugin::ProfileTest < ActiveRecord::TestCase
4   -
5   - def setup
6   - @profile = build(Profile)
7   - @invisible_profile = build(Enterprise, :visible => false)
8   - @other_profile = build(Enterprise)
9   - @profile = build(OrdersCyclePlugin::profile, :profile => @profile)
10   - @self_supplier = build(OrdersCyclePlugin::Supplier, :consumer => @profile, :profile => @profile)
11   - @dummy_supplier = build(OrdersCyclePlugin::Supplier, :consumer => @profile, :profile => @dummy_profile)
12   - @other_supplier = build(OrdersCyclePlugin::Supplier, :consumer => @profile, :profile => @other_profile)
13   - end
14   -
15   - attr_accessor :profile, :invisible_profile, :other_profile,
16   - :self_supplier, :dummy_supplier, :other_supplier
17   -
18   - should 'respond to name methods' do
19   - profile.expects(:name).returns('name')
20   - assert_equal 'name', profile.name
21   - end
22   -
23   - should 'respond to dummy methods' do
24   - profile.dummy = true
25   - assert_equal true, profile.dummy?
26   - profile.dummy = false
27   - assert_equal false, profile.dummy
28   - end
29   -
30   - should "return closed cycles' date range" do
31   - DateTime.expects(:now).returns(1).at_least_once
32   - assert_equal 1..1, profile.orders_cycles_closed_date_range
33   - s1 = create(OrdersCyclePlugin::Cycle, :profile => profile, :start => Time.now-1.days, :finish => nil)
34   - s2 = create(OrdersCyclePlugin::Cycle, :profile => profile, :finish => Time.now+1.days, :start => Time.now)
35   - assert_equal (s1.start.to_date..s2.finish.to_date), profile.orders_cycles_closed_date_range
36   - end
37   -
38   - should 'return abbreviation or the name' do
39   - profile.name_abbreviation = 'coll.'
40   - profile.profile.name = 'collective'
41   - assert_equal 'coll.', profile.abbreviation_or_name
42   - profile.name_abbreviation = nil
43   - assert_equal 'collective', profile.abbreviation_or_name
44   - end
45   -
46   - ###
47   - # Products
48   - ###
49   -
50   - should "default products's margins when asked" do
51   - profile.update_attributes! :margin_percentage => 10
52   - product = create(SuppliersPlugin::DistributedProduct, :profile => profile, :supplier => profile.self_supplier,
53   - :price => 10, :default_margin_percentage => false)
54   - cycle = create(OrdersCyclePlugin::Cycle, :profile => profile)
55   - sproduct = cycle.products.first
56   - sproduct.update_attributes! :margin_percentage => 5
57   - cycleclosed = create(OrdersCyclePlugin::Cycle, :profile => profile, :status => 'closed')
58   -
59   - profile.orders_cycles_products_default_margins
60   - product.reload
61   - sproduct.reload
62   - assert_equal true, product.default_margin_percentage
63   - assert_equal sproduct.margin_percentage, profile.margin_percentage
64   - end
65   -
66   - should 'return not yet distributed products' do
67   - profile.save!
68   - other_profile.save!
69   - other_supplier.save!
70   - product = create(SuppliersPlugin::DistributedProduct, :profile => other_profile, :supplier => other_profile.self_supplier)
71   - profile.add_supplier_products other_supplier
72   - product2 = create(SuppliersPlugin::DistributedProduct, :profile => other_profile, :supplier => other_profile.self_supplier)
73   - assert_equal [product2], profile.not_distributed_products(other_supplier)
74   - end
75   -
76   - ###
77   - # Suppliers
78   - ###
79   -
80   - should 'add supplier' do
81   - @profile.save!
82   - @other_profile.save!
83   -
84   - assert_difference OrdersCyclePlugin::Supplier, :count do
85   - @profile.add_supplier @other_profile
86   - end
87   - assert @profile.suppliers_profiles.include?(@other_profile)
88   - assert @other_profile.consumers_profiles.include?(@profile)
89   - end
90   -
91   - should "add all supplier's products when supplier is added" do
92   - @profile.save!
93   - @other_profile.save!
94   - product = create(SuppliersPlugin::DistributedProduct, :profile => @other_profile)
95   - @profile.add_supplier @other_profile
96   - assert_equal [product], @profile.from_products
97   - end
98   -
99   - should 'remove supplier' do
100   - @profile.save!
101   - @other_profile.save!
102   -
103   - @profile.add_supplier @other_profile
104   - assert_difference OrdersCyclePlugin::Supplier, :count, -1 do
105   - assert_difference RoleAssignment, :count, -1 do
106   - @profile.remove_supplier @other_profile
107   - end
108   - end
109   - assert !@profile.suppliers_profiles.include?(@other_profile)
110   - end
111   -
112   - should "archive supplier's products when supplier is removed" do
113   - @profile.save!
114   - @other_profile.save!
115   - product = create(SuppliersPlugin::DistributedProduct, :profile => @other_profile)
116   - @profile.add_supplier @other_profile
117   - @profile.remove_supplier @other_profile
118   - assert_equal [product], @profile.from_products
119   - assert_equal 1, @profile.distributed_products.archived.count
120   - end
121   -
122   - should 'create self supplier automatically' do
123   - profile = create(OrdersCyclePlugin::profile, :profile => @profile)
124   - assert_equal 1, profile.suppliers.count
125   - end
126   -
127   -end
plugins/shopping_cart/delivery_admin.feature 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +Feature: delivery administration
  2 + As an enterprise's administrator
  3 + I want to create delivery methods
  4 + In order to allow my customer to choose which delivery they want
  5 +
  6 + Background:
  7 + Given "ShoppingCart" plugin is enabled
  8 + And "Delivery" plugin is enabled
  9 + And the following users
  10 + | login | name |
  11 + | moe | Moe |
  12 + And the following enterprise
  13 + | identifier | name | owner |
  14 + | moes-tavern | Moes Tavern | moe |
  15 + And the shopping basket is enabled on "Moes Tavern"
  16 + And "Moe" is admin of "Moes Tavern"
  17 + And I am logged in as "moe"
  18 + And I go to moes-tavern's control panel
  19 +
  20 + @selenium
  21 + Scenario: enable delivery
  22 + Given I follow "Shopping basket"
  23 + When I check "Enable shopping basket"
  24 + Then I should see "Deliveries or pickups"
  25 +
  26 + @selenium
  27 + Scenario: disable delivery
  28 + Given I follow "Shopping basket"
  29 + When I uncheck "Enable shopping basket"
  30 + Then I should not see "Deliveries or pickups"
  31 +
  32 + @selenium
  33 + Scenario: create new deliver
  34 + Given I follow "Shopping basket"
  35 + And I check "Enable shopping basket"
  36 + And I follow "New delivery or pickup"
  37 + And I select "Deliver" from "Type"
  38 + And I fill in "Name" with "Bike"
  39 + And I fill in "Description" with "Beers delivered with my old bike."
  40 + And I fill in "Fixed cost" with "8.00"
  41 + And I fill in "Order's minimum price for free delivery" with "35.50"
  42 + When I press "Add"
  43 + Then I should see "Bike" within ".delivery-method"
  44 +
  45 + @selenium
  46 + Scenario: create new pickup
  47 + Given I follow "Shopping basket"
  48 + And I check "Enable shopping basket"
  49 + And I follow "New delivery or pickup"
  50 + And I select "Pickup" from "Type"
  51 + And I fill in "Name" with "Bar"
  52 + And I fill in "Description" with "Come to my bar and pick it yourself."
  53 + And I fill in "Fixed cost" with "0.00"
  54 + When I press "Add"
  55 + Then I should see "Bar"
  56 +
  57 + @selenium
  58 + Scenario: remove delivery
  59 + Given I follow "Shopping basket"
  60 + And I check "Enable shopping basket"
  61 + And I follow "New delivery or pickup"
  62 + And I fill in "Name" with "Bike"
  63 + When I press "Add"
  64 + Then I should see "Bike"
  65 + And I follow "Remove" within ".delivery-method"
  66 + When I confirm the browser dialog
  67 + Then I should see "Bike"
  68 +
  69 + @selenium
  70 + Scenario: edit delivery
  71 + Given I follow "Shopping basket"
  72 + And I check "Enable shopping basket"
  73 + And I follow "New delivery or pickup"
  74 + And I fill in "Name" with "Bike"
  75 + When I press "Add"
  76 + Then I should see "Bike"
  77 + And I follow "Edit" within ".delivery-method"
  78 + And I fill in "Name" with "Car"
  79 + When I press "Save"
  80 + Then I should not see "Bike"
  81 + Then I should see "Car"
... ...
plugins/shopping_cart/delivery_client.feature 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +Feature: delivery client
  2 + As an enterprise's client
  3 + I want to choose the delivery method
  4 + In order to receive my procucts properly
  5 +
  6 + Background:
  7 + Given "ShoppingCart" plugin is enabled
  8 + And "Delivery" plugin is enabled
  9 + And the following users
  10 + | login | name | email |
  11 + | moe | Moe | moe@springfield.com |
  12 + | homer | Homer | homer@springfield.com |
  13 + And the following enterprise
  14 + | identifier | name | owner |
  15 + | moes-tavern | Moes Tavern | moe |
  16 + And the shopping basket is enabled on "Moes Tavern"
  17 + And the following product_categories
  18 + | name |
  19 + | Beer |
  20 + | Snacks |
  21 + And the following products
  22 + | owner | category | name | price |
  23 + | moes-tavern | beer | Duff | 3.00 |
  24 + | moes-tavern | snacks | French fries | 7.00 |
  25 + And "moes-tavern" has the following delivery methods
  26 + | delivery_type | name | description | fixed_cost | free_over_price |
  27 + | deliver | Bike | My good old bike. | 8.00 | 10.00 |
  28 + | pickup | Bar | Come to my bar and drink it! | 0.00 | 0.00 |
  29 + And feature "products_for_enterprises" is enabled on environment
  30 + And I am logged in as "homer"
  31 + And I go to moes-tavern's products page
  32 +
  33 + @selenium
  34 + Scenario: choose deliver method for purchase
  35 + Given I follow "Add to basket"
  36 + And I follow "Add to basket"
  37 + And I should see "Show basket"
  38 + And I follow "Show basket"
  39 + And I follow "Shopping checkout"
  40 + And I fill in "Contact phone" with "123456789"
  41 + When I select "Bike ($8.00)" from "Option"
  42 + Then I should see "My good old bike." within ".instructions"
  43 + And I should see "Address"
  44 + And I should see "Bike" within "#delivery-name"
  45 + And I should see "8.00" within "#delivery-price"
  46 +
  47 + @selenium
  48 + Scenario: choose pickup method for purchase
  49 + Given I follow "Add to basket"
  50 + And I follow "Add to basket"
  51 + And I should see "Show basket"
  52 + And I follow "Show basket"
  53 + And I follow "Shopping checkout"
  54 + And I fill in "Contact phone" with "123456789"
  55 + When I select "Bar" from "Option"
  56 + Then I should see "Come to my bar and drink it!" within ".instructions"
  57 + And I should not see "Address"
  58 + And I should see "Bar" within "#delivery-name"
  59 + And I should see "0.00" within "#delivery-price"
  60 +
  61 + @selenium
  62 + Scenario: gets free delivery due to free over price
  63 + Given I follow "Add to basket"
  64 + And I follow "Add to basket"
  65 + And I follow "Add to basket"
  66 + And I follow "Add to basket"
  67 + And I follow "Add to basket"
  68 + And I follow "Add to basket"
  69 + And I should see "Show basket"
  70 + And I follow "Show basket"
  71 + And I follow "Shopping checkout"
  72 + And I fill in "Contact phone" with "123456789"
  73 + When I select "Bike ($8.00)" from "Option"
  74 + Then I should see "My good old bike." within ".instructions"
  75 + And I should see "Address"
  76 + And I should see "Bike" within "#delivery-name"
  77 + And I should see "0.00" within "#delivery-price"
... ...
plugins/shopping_cart/install.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +system "script/noosfero-plugins -q enable orders delivery"
  2 +
... ...
plugins/shopping_cart/plugin.yml
... ... @@ -1,3 +0,0 @@
1   -name: shopping_cart
2   -dependencies:
3   - - orders
plugins/shopping_cart/step_definitions/delivery_steps.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name|
  2 + status = status == 'enabled'
  3 + enterprise = Enterprise.find_by_name(name) || Enterprise[name]
  4 + settings = enterprise.shopping_cart_settings({:enabled => status})
  5 + settings.save!
  6 +end
  7 +
  8 +Given /^"([^""]*)" has the following delivery methods$/ do |name, table|
  9 + enterprise = Enterprise.find_by_name(name) || Enterprise[name]
  10 + table.hashes.map{|item| item.dup}.each do |item|
  11 + delivery_method = enterprise.delivery_methods.build
  12 + delivery_method.update_attributes(item)
  13 + end
  14 +end
... ...
plugins/suppliers/test/test_helper.rb
... ... @@ -1 +0,0 @@
1   -require File.dirname(__FILE__) + '/../../../test/test_helper'
plugins/suppliers/test/unit/code_numbering_test.rb
... ... @@ -1,7 +0,0 @@
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -
3   -class CodeNumberingTest < ActiveSupport::TestCase
4   -
5   -
6   -end
7   -
plugins/suppliers/test/unit/default_delegate_test.rb
... ... @@ -1,6 +0,0 @@
1   -require 'test_helper'
2   -
3   -class DefaultDelegateTest < ActiveSupport::TestCase
4   -
5   -
6   -end
plugins/suppliers/test/unit/suppliers_plugin/distributed_product_test.rb
... ... @@ -1,108 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class SuppliersPlugin::DistributedProductTest < ActiveSupport::TestCase
4   -
5   - def setup
6   - @product_category = create(ProductCategory, :name => 'parent')
7   - @profile = build(Enterprise)
8   - @invisible_profile = build(Enterprise, :visible => false)
9   - @other_profile = build(Enterprise)
10   - @self_supplier = build(SuppliersPlugin::Supplier, :consumer => @profile, :profile => @profile)
11   - @dummy_supplier = build(SuppliersPlugin::Supplier, :consumer => @profile, :profile => @dummy_profile)
12   - @other_supplier = build(SuppliersPlugin::Supplier, :consumer => @profile, :profile => @other_profile)
13   - end
14   -
15   - attr_accessor :product_category,
16   - :profile, :invisible_profile, :other_profile,
17   - :profile, :dummy_profile, :other_profile, :self_supplier, :dummy_supplier, :other_supplier
18   -
19   - should 'return default settings considering dummy supplier' do
20   - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @dummy_supplier)
21   - assert_equal nil, product.default_name
22   - assert_equal nil, product.default_description
23   - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @other_supplier)
24   - assert_equal true, product.default_name
25   - assert_equal true, product.default_description
26   - end
27   -
28   - should 'return price without margins if it is own product' do
29   - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @profile, :supplier => @self_supplier)
30   - assert_equal 10.0, product.price.to_f
31   - end
32   -
33   - should 'return price without margins if supplier product has no price' do
34   - supplier_product = build(SuppliersPlugin::DistributedProduct, :profile => @other_profile, :supplier => @other_profile.self_supplier)
35   - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @profile, :supplier => @other_supplier)
36   - assert_equal 10.0, product.price.to_f
37   - end
38   -
39   - should 'return price with margins' do
40   - supplier_product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @other_profile, :supplier => @other_profile.self_supplier)
41   - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :supplier_product => supplier_product, :profile => @profile, :supplier => @other_supplier)
42   -
43   - product.default_margin_percentage = false
44   - assert_equal 11.0, product.price.to_f
45   - profile.margin_percentage = 20
46   - product.default_margin_percentage = true
47   - assert_equal 12.0, product.price.to_f
48   - end
49   -
50   - should 'allow set of supplier product' do
51   - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @profile, :supplier => @self_supplier)
52   -
53   - product.from_product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @self_supplier)
54   - assert_nothing_raised do
55   - product.supplier_product = {:price => 10, :margin_percentage => 10}
56   - product.supplier_product = SuppliersPlugin::DistributedProduct.new :price => 5
57   - end
58   - end
59   -
60   - should 'create a supplier product for a dummy supplier' do
61   - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @dummy_supplier)
62   - assert product.supplier_product
63   - # negative assertion
64   - product = build(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @other_supplier)
65   - assert !product.supplier_product
66   - end
67   -
68   - should 'respond to supplier_product_id setter and getter' do
69   - product = create(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @dummy_supplier)
70   - assert_equal product.supplier_product.id, product.supplier_product_id
71   - product.expects(:distribute_from)
72   - product.supplier_product_id = 1
73   - end
74   -
75   - should 'respond to distribute_from' do
76   - product = create(SuppliersPlugin::DistributedProduct, :profile => @profile, :supplier => @profile.self_supplier)
77   -
78   - assert_raise RuntimeError do
79   - supplier_product = build(SuppliersPlugin::DistributedProduct, :profile => @other_profile)
80   - product.distribute_from(supplier_product)
81   - end
82   -
83   - supplier_product = create(SuppliersPlugin::DistributedProduct, :profile => @other_profile)
84   - product.profile.add_supplier @other_profile
85   - product.distribute_from supplier_product
86   - assert_equal product.supplier.profile, supplier_product.profile
87   - assert_equal product.supplier.profile, supplier_product.profile
88   - end
89   -
90   - should 'return json for category hierarchy' do
91   - grandparent = create(ProductCategory, :name => 'grand parent')
92   - parent = create(ProductCategory, :name => 'parent')
93   - child = product_category
94   -
95   - product = SuppliersPlugin::DistributedProduct.new :category => parent
96   - hash = {:own_name => "parent", :id => "2", :subcats => [], :name => "parent",
97   - :hierarchy => [{:own_name => "parent", :subcats => [], :name => "parent", :id => "2"}]}
98   - assert_equal hash, product.json_for_category
99   - end
100   -
101   - should 'block own product distribution' do
102   - product = Product.create :enterprise => @profile, :product_category => product_category
103   - distributed = SuppliersPlugin::DistributedProduct.new :enterprise => @profile, :from_products => [product]
104   -
105   - assert distributed.invalid?
106   - end
107   -
108   -end
plugins/suppliers/test/unit/suppliers_plugin/product_test.rb
... ... @@ -1,49 +0,0 @@
1   -require "test_helper"
2   -
3   -class SuppliersPlugin::ProductTest < ActiveSupport::TestCase
4   -
5   - def setup
6   - @product = build(SuppliersPlugin::BaseProduct)
7   - end
8   -
9   - should 'return first from product as supplier product' do
10   - fp = build(SuppliersPlugin::BaseProduct, :profile => @product.profile)
11   - @product.from_products = [fp]
12   - assert_equal fp, @product.from_product
13   - assert_equal fp, @product.supplier_product
14   - end
15   -
16   - should 'respond to dummy and own' do
17   - assert !@product.dummy?
18   - assert @product.own?
19   - end
20   -
21   - should 'return price with margins' do
22   - supplier_product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :profile => @product.profile, :supplier => @product.profile.self_supplier)
23   - product = build(SuppliersPlugin::DistributedProduct, :price => 10, :margin_percentage => 10, :supplier_product => supplier_product, :profile => @product.profile, :supplier => @product.profile.self_supplier)
24   -
25   - product.default_margin_percentage = false
26   - assert_equal 11.0, product.price_with_margins
27   - @product.profile.margin_percentage = 20
28   - product.default_margin_percentage = true
29   - assert_equal 12.0, product.price_with_margins
30   - end
31   -
32   - should 'build default unit if none exists' do
33   - assert_equal 0, Unit.count
34   - assert 'unit', @product.unit.singular
35   - end
36   -
37   - should 'avoid destroy by raising an exception' do
38   - assert_raise RuntimeError do
39   - @product.destroy
40   - end
41   - end
42   -
43   - should 'accept price in different formats' do
44   - @product.price = '2,45'
45   - assert_equal 2.45, @product.price
46   - end
47   -
48   -
49   -end
plugins/suppliers/test/unit/suppliers_plugin/source_product_test.rb
... ... @@ -1,8 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class SuppliersPlugin::SourceProductTest < ActiveSupport::TestCase
4   -
5   - def setup
6   - end
7   -
8   -end
plugins/suppliers/test/unit/suppliers_plugin/supplier_test.rb
... ... @@ -1,8 +0,0 @@
1   -require "#{File.dirname(__FILE__)}/../../test_helper"
2   -
3   -class SuppliersPlugin::SupplierTest < ActiveSupport::TestCase
4   -
5   - def setup
6   - end
7   -
8   -end
plugins/volunteers/lib/split_datetime.rb
... ... @@ -1,72 +0,0 @@
1   -
2   -module SplitDatetime
3   -
4   - class << self
5   - def nil_time
6   - Time.parse "#{Time.now.hour}:0:0"
7   - end
8   - def nil_date
9   - Date.today
10   - end
11   -
12   - def to_time datetime
13   - datetime = self.nil_time if datetime.blank?
14   - datetime.to_formatted_s :time
15   - end
16   - def to_date datetime
17   - datetime = self.nil_date if datetime.blank?
18   - datetime.strftime '%d/%m/%Y'
19   - end
20   - def set_time datetime, value
21   - value = if value.blank?
22   - self.nil_time
23   - elsif value.kind_of? String
24   - Time.parse value
25   - else
26   - value.to_time
27   - end
28   - datetime = self.nil_date if datetime.blank?
29   -
30   - Time.mktime(datetime.year, datetime.month, datetime.day, value.hour, value.min, value.sec).to_datetime
31   - end
32   - def set_date datetime, value
33   - value = if value.blank?
34   - self.nil_date
35   - elsif value.kind_of? String
36   - DateTime.strptime value, '%d/%m/%Y'
37   - else
38   - value.to_time
39   - end
40   - datetime = nil_time if datetime.blank?
41   -
42   - Time.mktime(value.year, value.month, value.day, datetime.hour, datetime.min, datetime.sec).to_datetime
43   - end
44   - end
45   -
46   - module SplitMethods
47   -
48   - def split_datetime attr
49   - define_method "#{attr}_time" do
50   - datetime = send attr
51   - SplitDatetime.to_time datetime
52   - end
53   - define_method "#{attr}_date" do
54   - datetime = send attr
55   - SplitDatetime.to_date datetime
56   - end
57   - define_method "#{attr}_time=" do |value|
58   - datetime = send attr
59   - send "#{attr}=", SplitDatetime.set_time(datetime, value)
60   - end
61   - define_method "#{attr}_date=" do |value|
62   - datetime = send attr
63   - send "#{attr}=", SplitDatetime.set_date(datetime, value)
64   - end
65   - end
66   -
67   - end
68   -
69   -end
70   -
71   -Class.extend SplitDatetime::SplitMethods
72   -ActiveRecord::Base.extend SplitDatetime::SplitMethods
plugins/volunteers/test/unit/split_datetime_test.rb
... ... @@ -1,53 +0,0 @@
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -
3   -class ModelWithDate
4   -
5   - def initialize
6   - @delivery = DateTime.now
7   - end
8   -
9   - attr_accessor :delivery
10   -
11   - extend SplitDatetime::SplitMethods
12   - split_datetime :delivery
13   -
14   -end
15   -
16   -class SplitDatetimeTest < ActiveSupport::TestCase
17   -
18   - def setup
19   - @m = ModelWithDate.new
20   - @m.delivery = (Time.mktime(2011) + 2.hours + 2.minutes + 2.seconds).to_datetime
21   - end
22   -
23   - should 'return get splitted times' do
24   - assert_equal @m.delivery_date, '2011-01-01'
25   - assert_equal @m.delivery_time, '02:02'
26   - end
27   -
28   - should 'return set splitted times by Date' do
29   - @m.delivery_date = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime
30   - assert_equal @m.delivery_date, '2011-03-05'
31   - assert_equal @m.delivery_time, '02:02'
32   - end
33   -
34   - should 'return set splitted times by Time' do
35   - @m.delivery_time = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime
36   - assert_equal @m.delivery_date, '2011-01-01'
37   - assert_equal @m.delivery_time, '03:03'
38   - end
39   -
40   - should 'return set splitted times by Date String' do
41   - @m.delivery_date = "2011-11-11"
42   - assert_equal @m.delivery_date, '2011-11-11'
43   - assert_equal @m.delivery_time, '02:02'
44   - end
45   -
46   - should 'return set splitted times by Time String' do
47   - @m.delivery_time = "15:43"
48   - assert_equal @m.delivery_date, '2011-01-01'
49   - assert_equal @m.delivery_time, '15:43'
50   - end
51   -
52   -end
53   -
test/unit/split_datetime_test.rb 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +require 'test_helper'
  2 +
  3 +class ModelWithDate
  4 +
  5 + def initialize
  6 + @delivery = DateTime.now
  7 + end
  8 +
  9 + attr_accessor :delivery
  10 +
  11 + extend SplitDatetime::SplitMethods
  12 + split_datetime :delivery
  13 +
  14 +end
  15 +
  16 +class SplitDatetimeTest < ActiveSupport::TestCase
  17 +
  18 + def setup
  19 + @m = ModelWithDate.new
  20 + @m.delivery = (Time.mktime(2011) + 2.hours + 2.minutes + 2.seconds).to_datetime
  21 + end
  22 +
  23 + should 'return get splitted times' do
  24 + assert_equal '01/01/2011', @m.delivery_date
  25 + assert_equal '02:02', @m.delivery_time
  26 + end
  27 +
  28 + should 'return set splitted times by Date' do
  29 + @m.delivery_date = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime
  30 + assert_equal '05/03/2011', @m.delivery_date
  31 + assert_equal '02:02', @m.delivery_time
  32 + end
  33 +
  34 + should 'return set splitted times by Time' do
  35 + @m.delivery_time = (Time.mktime(2011, 3, 5) + 3.hours + 3.minutes + 3.seconds).to_datetime
  36 + assert_equal '01/01/2011', @m.delivery_date
  37 + assert_equal '03:03', @m.delivery_time
  38 + end
  39 +
  40 + should 'return set splitted times by Date String' do
  41 + @m.delivery_date = "11/11/2011"
  42 + assert_equal '11/11/2011', @m.delivery_date
  43 + assert_equal '02:02', @m.delivery_time
  44 + end
  45 +
  46 + should 'return set splitted times by Time String' do
  47 + @m.delivery_time = "15:43"
  48 + assert_equal '01/01/2011', @m.delivery_date
  49 + assert_equal '15:43', @m.delivery_time
  50 + end
  51 +
  52 +end
  53 +
... ...